当前位置:网站首页>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;
}
边栏推荐
- 程序员女友给我做了一个疲劳驾驶检测
- LeetCode 1380. Lucky number in matrix
- 嵌入式系统开发笔记81:使用Dialog组件设计提示对话框
- 165. compare version numbers
- 有效的 @SuppressWarnings 警告名称
- 【人话版】WEB3黑暗森林中的隐私博弈
- 陈宇(Aqua)-安全-&gt;云安全-&gt;多云安全
- Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly
- 多次跳槽后,月薪等于老同事的年薪
- JMeter login failure, extracting login token, and obtaining token problem solving
猜你喜欢
283. move zero
Unexpected token o in JSON at position 1, JSON parsing problem
Possible problems and solutions of using scroll view to implement slider view
206. reverse linked list
Custom components in applets
It's settled! 2022 JD cloud summit of JD global technology Explorer conference see you in Beijing on July 13
Hololens2 development environment building and deploying apps
Web components series (VIII) -- custom component style settings
Embedded System Development Notes 79: why should I get the IP address of the local network card
Volley parsing data shows networking failure
随机推荐
Mallbook: how can hotel enterprises break the situation in the post epidemic era?
【人话版】WEB3黑暗森林中的隐私博弈
Possible problems and solutions of using scroll view to implement slider view
LeetCode 1380. Lucky number in matrix
【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
318. Maximum word length product
LeetCode 1400. Construct K palindrome strings
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
The programmer's girlfriend gave me a fatigue driving test
Redis (VII) optimization suggestions
Note de développement du système embarqué 80: application du concepteur Qt à la conception de l'interface principale
Concurrent mode of different performance testing tools
LeetCode 1827. Increment array with minimal operation
Knowledge supplement: redis' basic data types and corresponding commands
什么是uid?什么是Auth?什么是验证器?
TS type gymnastics: illustrating a complex advanced type
392. judgment subsequence
嵌入式系统开发笔记81:使用Dialog组件设计提示对话框
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
Future of NTF and trends in 2022