当前位置:网站首页>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) 因为大概每次询问最多分裂两个区间
或者询问区间贡献和 每次下放 的时候直接下放纯色区间 查询的时候也直接一直往下走 走到纯色的地方 注意 染色之后需要合并懒标记
边栏推荐
- Ubuntu下使用sudo dpkg --configure -a后数据库出现问题
- 【小码匠自习室】让错误成为孩子进步的阶梯
- Is it safe to open an account online now?Which securities to choose for securities account opening?
- 连这几个网站都不知道,怪不得你的消息比别人落后
- 软考 --- 软件工程(6)软项目管理
- Common regularization methods in deep learning (Regularization) and detailed explanation of WeightDecay parameters in optimizers
- 电商秒杀系统架构设计
- 从洞察到决策,一文解读标签画像体系建设方法论丨DTVision分析洞察篇
- sqllabs 1~6通关详解
- vsomeip环境搭建及helloworld测试例跑通
猜你喜欢
随机推荐
CS231n:6 训练神经网络(二)
PHP —— CI 框架实现微信小程序支付
Introduction to Recurrent Neural Network (RNN)
第一章、RPC 基础知识
[内部资源] 想拿年薪30W的软件测试人员,这份资料必须领取
在中国银河证券开户安全吗 齐齐哈尔股票开户
JS-Bom-while(计算闰年)
领域驱动设计系列贫血模型和充血模型
JS加法器(DOM)
JS - BOM - - can be achieved through calculation or default values
投资一个约20台桩的充电站需要多少钱?多久可以实现盈利?
一万块钱能做一手尿素期货吗?尿素期货怎么做才安全?
深度学习-神经网络原理1
MySQL中UNION和UNION ALL的区别
2022-08-07 第五小组 顾祥全 学习笔记 day31-集合-Map集合
RecyclerView 实现拖拽、滑动删除
2022-08-07 The fifth group Gu Xiangquan study notes day31-collection-Map collection
优雅地实时检测和更新 Web 应用
什么是低代码开发?大家都真的看好低代码开发吗?
"Small yards artisan study room" friends of friends is not a friend