当前位置:网站首页>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
边栏推荐
猜你喜欢
Elegantly detect and update web applications in real time
我凭借这份pdf成功拿到了阿里,腾讯,京东等六家大厂offer
JS - BOM - - can be achieved through calculation or default values
JS Adder (DOM)
Fast DDS 共享内存测试例修改栈空间大小的方式-如改为30M
[内部资源] 想拿年薪30W的软件测试人员,这份资料必须领取
2022年8月中国数据库排行榜:openGauss重夺榜眼,PolarDB反超人大金仓
什么是低代码开发?大家都真的看好低代码开发吗?
Superset 1.2.0 安装
创建二维数组
随机推荐
解决Redis、MySQL缓存双写不一致问题
兆骑科创赛事服务平台对接,海内外高层次人才引进
Superset 1.2.0 安装
循环神经网络RNN入门介绍
电商秒杀系统架构设计
浏览器跨域方案,适用于本地调试接口(超简单)
Iptables防火墙iprange模块扩展匹配规则
并发请求如何优雅地处理重复请求
基于微信小程序的幼儿园招生报名系统开发笔记
sqoop连接MySQL跟本机不一致是为什么
PHP —— 用 ThinkPHP5.0 实现微信小程序登陆
kali换源详细步骤
1052. 爱生气的书店老板
JS Adder (DOM)
领域驱动设计系列贫血模型和充血模型
token系统讲解及过期处理
在中国银河证券开户安全吗 齐齐哈尔股票开户
一文读懂字节跳动“埋点验证平台”
【服务器数据恢复】Ext4文件系统fsck后mount不上并报错的数据修复案例
增效降本开源节流,2022年技术趋势前瞻(异步编程/容器技术)