当前位置:网站首页>codeforces 444C DZY Loves Colors
codeforces 444C DZY Loves Colors
2022-08-08 15:14: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 .
One interval can be covered at a time Then each overwrite gets some benefit 即 abs(v-a[i]) 那么 It is directly similar to the line segment sloth marker 复杂度大约是(n+m)log(n) Because presumably each query splits at most two intervals
Or ask about the interval contribution sum every release When it is time to directly lower the solid color range When inquiring, go straight down Go to a solid color 注意 Lazy markers need to be merged after staining
边栏推荐
- Common regularization methods in deep learning (Regularization) and detailed explanation of WeightDecay parameters in optimizers
- Power BI简介
- JDBC工具类的封装及使用
- 【对线面试官】如何实现去重和幂等
- What is low-code development?Is everyone really optimistic about low-code development?
- UOJ#748-[UNR #6]机器人表演【dp】
- 依赖传递和依赖调解
- JS-BOM-for, if (string to case)
- JS-Bom-while (calculate leap year)
- Ubuntu下使用sudo dpkg --configure -a后数据库出现问题
猜你喜欢
随机推荐
bandanas Kerchief头巾是何含义?
token系统讲解及过期处理
想要精准营销,从学习搭建一套对的标签体系开始丨 DTVision 分析洞察篇
什么是发饰hair accessories?
一万块钱能做一手尿素期货吗?尿素期货怎么做才安全?
sqoop连接MySQL跟本机不一致是为什么
CS231n:6 训练神经网络(二)
[内部资源] 想拿年薪30W的软件测试人员,这份资料必须领取
想去银行测试?那这套题目你必须要会
HMS Core分析服务智能运营6.5.1版本上线
Brief description of the state of the thread
bzoj3262 陌上花开
PHP —— 用 ThinkPHP5.0 实现微信小程序登陆
大佬们,sqlserver-cdc任务报错这个,大家遇到过吗Caused by: org.apac
JS-Bom-while(计算闰年)
Mysql的分布式事务原理理解
面试官:Redis 大 key 要如何处理?
SAP系统为什么要迁移上云?
Superset 1.2.0 安装
面试官:Redis 大 key 要如何处理?