当前位置:网站首页>codeforces 444C DZY Loves Colors
codeforces 444C DZY Loves Colors
2022-08-08 14:58:00 【51CTO】
http://www.elijahqi.win/2018/03/07/codeforces-444c/
题目描述
DZY loves colors, and he enjoys painting.
On a colorful day, DZY gets a colorful ribbon, which consists of
n
n units (they are numbered from
1
1 to
n
n from left to right). The color of the
i
i -th unit of the ribbon is
i
i at first. It is colorful enough, but we still consider that the colorfulness of each unit is
0
0 at first.
DZY loves painting, we know. He takes up a paintbrush with color
x
x and uses it to draw a line on the ribbon. In such a case some contiguous units are painted. Imagine that the color of unit
i
i currently is
y
y . When it is painted by this paintbrush, the color of the unit becomes
x
x , and the colorfulness of the unit increases by
|x-y|
∣x−y∣ .
DZY wants to perform
m
m operations, each operation can be one of the following:
Paint all the units with numbers between
l
l and r
r (both inclusive) with color x
x .
Ask the sum of colorfulness of the units between
l
l and r
r (both inclusive).
Can you help DZY?
输入输出格式
输入格式:
The first line contains two space-separated integers n,m(1<=n,m<=105) n , m ( 1 <= n , m <= 10 5 )
Each of the next
m
m lines begins with a integer type(1<=type<=2) t y p e ( 1 <= t y p e <= 2 )
If
type=1
type=1 , there will be
3
3 more integers l,r,x(1<=l<=r<=n;1<=x<=108) l , r , x ( 1 <= l <= r <= n ; 1 <= x <= 10 8 )
1
1 .
If
type=2
type=2 , there will be
2
2 more integers l,r(1<=l<=r<=n) l , r ( 1 <= l <= r <= n )
2
2 .
输出格式:
For each operation
2
2 , print a line containing the answer — sum of colorfulness.
输入输出样例
输入样例#1: 复制
3 3
1 1 2 4
1 2 3 5
2 1 3
输出样例#1: 复制
8
输入样例#2: 复制
3 4
1 1 3 4
2 1 1
2 2 2
2 3 3
输出样例#2: 复制
3
2
1
输入样例#3: 复制
10 6
1 1 5 3
1 2 7 9
1 10 10 11
1 3 8 12
1 1 10 3
2 1 10
输出样例#3: 复制
129
说明
In the first sample, the color of each unit is initially
[1,2,3]
[1,2,3] , and the colorfulness is
[0,0,0]
[0,0,0] .
After the first operation, colors become
[4,4,3]
[4,4,3] , colorfulness become
[3,2,0]
[3,2,0] .
After the second operation, colors become
[4,5,5]
[4,5,5] , colorfulness become
[3,3,2]
[3,3,2] .
So the answer to the only operation of type
2
2 is
8
8 .
每次可以覆盖一个区间 然后每次覆盖都会获得一些收益 即 abs(v-a[i]) 那么 直接类似线段树懒标记即可 复杂度大约是(n+m)log(n) 因为大概每次询问最多分裂两个区间
或者询问区间贡献和 每次下放 的时候直接下放纯色区间 查询的时候也直接一直往下走 走到纯色的地方 注意 染色之后需要合并懒标记
边栏推荐
猜你喜欢
随机推荐
小程序轮播图实现由远及近动画
想要精准营销,从学习搭建一套对的标签体系开始丨 DTVision 分析洞察篇
2022年8月中国数据库排行榜:openGauss重夺榜眼,PolarDB反超人大金仓
第一章、RPC 基础知识
JS-Bom-while (calculate leap year)
依赖传递和依赖调解
【小码匠自习室】朋友的朋友不是朋友
Talking about the underlying data structure of Redis
[Small Coder Study Room] ABC179-C: It is a miracle that the code does not count down
领域驱动设计系列贫血模型和充血模型
解决Redis、MySQL缓存双写不一致问题
什么是幂等性
儿子满墙奖状却没考上重点高中,妈妈愤怒撕下痛哭:不读出去打工
想去银行测试?那这套题目你必须要会
并发请求如何优雅地处理重复请求
【控制】动力学建模举例 --> 牛顿-欧拉法
面试题 17.05. 字母与数字
1
JS-BOM-for,if(字符串转大小写)
Brief description of the state of the thread