当前位置:网站首页>CF1638E colorful operations
CF1638E colorful operations
2022-07-01 04:07:00 【solemntee】

Consider using a segment tree to maintain .
If a certain section has the same color , Are all x x x, Then change the color of this paragraph to y y y It is equivalent to adding the current color first l a z [ x ] laz[x] laz[x] And then subtract the color l a z [ y ] laz[y] laz[y] The contribution of . q u e r y query query When output q u e r y ( x ) + l a z [ c o l o r [ x ] ] query(x)+laz[color[x]] query(x)+laz[color[x]] that will do , Because every time the color is modified, the interval is assigned , So the complexity is shared equally .
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define ms l+r>>1
#define ls p<<1
#define rs p<<1|1
ll lazC[4000005],lazV[4000005];
int color[4000005];
ll LAZ[4000005];
bool cover[4000005];
void pushup(int p,int l,int r)
{
if(cover[ls]&&cover[rs]&&(color[ls]==color[rs]))
{
cover[p]=1;
color[p]=color[ls];
}
else cover[p]=0;
}
void build(int p,int l,int r)
{
cover[p]=1;
lazC[p]=1;
color[p]=1;
if(l==r)return;
int mid=ms;
build(ls,l,mid);
build(rs,mid+1,r);
pushup(p,l,r);
}
void update(int p,int l,int r,int x,int y,int w);
void pushdown(int p,int l,int r)
{
if(lazC[p])
{
lazC[ls]=lazC[p];
cover[ls]=1;
lazC[rs]=lazC[p];
cover[rs]=1;
color[ls]=lazC[p];
color[rs]=lazC[p];
lazC[p]=0;
}
if(lazV[p])
{
lazV[ls]+=lazV[p];
lazV[rs]+=lazV[p];
lazV[p]=0;
}
}
void update(int p,int l,int r,int x,int y,int w)
{
if(l>=x&&r<=y&&cover[p])
{
lazV[p]+=LAZ[color[p]]-LAZ[w];
lazC[p]=w;
color[p]=w;
return ;
}
int mid=ms;
pushdown(p,l,r);
if(x<=mid)update(ls,l,mid,x,y,w);
if(y>mid)update(rs,mid+1,r,x,y,w);
pushup(p,l,r);
}
long long query(int p,int l,int r,int x)
{
if(l==r)
{
// printf("color=%d val=%lld\n",color[p],lazV[p]);
return lazV[p]+LAZ[color[p]];
}
pushdown(p,l,r);
int mid=ms;
if(x<=mid)return query(ls,l,mid,x);
else return query(rs,mid+1,r,x);
pushup(p,l,r);
}
int main()
{
int n,q;
scanf("%d%d",&n,&q);
build(1,1,n);
for(int i=1;i<=q;i++)
{
char s[10];
scanf("%s",s+1);
if(s[1]=='C')
{
int l,r,c;
scanf("%d%d%d",&l,&r,&c);
update(1,1,n,l,r,c);
}
else if(s[1]=='A')
{
int c,x;
scanf("%d%d",&c,&x);
LAZ[c]+=x;
}
else if(s[1]=='Q')
{
int x;
scanf("%d",&x);
printf("%lld\n",query(1,1,n,x));
}
}
return 0;
}
边栏推荐
- Libevent Library Learning
- [TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
- [send email with error] 535 error:authentication failed
- 206. reverse linked list
- Go learning --- unit test subtest
- What does ft mean in the data book table
- 创新界,聚势行 | 2022人大金仓“百城巡展”火热开启
- 431. 将 N 叉树编码为二叉树 DFS
- 使用scroll-view实现滑块视图可能遇到的问题及其解决方法
- 214. minimum palindrome string
猜你喜欢

多次跳槽后,月薪等于老同事的年薪

Custom components in applets

线程常用方法与守护线程
![[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation](/img/49/173b1f1f379faa28c503165a300ce0.png)
[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation

Huawei simulator ENSP - hcip - Hybrid Experiment 2

程序员女友给我做了一个疲劳驾驶检测
![[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation](/img/4e/8cf60bc816441967c04f97c64685a1.png)
[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation

Hololens2 development environment building and deploying apps

类和对象收尾

ThreeJS开篇
随机推荐
72. edit distance
Jenkins automatically cleans up construction history
Grid system in bootstrap
Coinbase in a bear market: losses, layoffs, stock price plunges
Go learning --- unit test subtest
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
LeetCode 1399. Count the maximum number of groups
什么是权限?什么是角色?什么是用户?
Qt开发经验小技巧226-230
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
[EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
基于Unet的环路滤波
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
The programmer's girlfriend gave me a fatigue driving test
Unexpected token o in JSON at position 1, JSON parsing problem
25.k sets of flipped linked lists
205. isomorphic string
[TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
Recommend the best product development process in the Internet industry!