当前位置:网站首页>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;
}
边栏推荐
- [untitled] Li Kou 496 Next larger element I
- 214. minimum palindrome string
- Future of NTF and trends in 2022
- Qt development experience tips 226-230
- Analysis and case of pageobject mode
- [JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
- Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
- LetCode 1829. Maximum XOR value per query
- 使用WinMTR软件简单分析跟踪检测网络路由情况
- mysql 函数 变量 存储过程
猜你喜欢

【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算

互联网行业最佳产品开发流程 推荐!

分账技术赋能农贸市场,重塑交易管理服务效能

Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)

After many job hopping, the monthly salary is equal to the annual salary of old colleagues

JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction

【TA-霜狼_may-《百人计划》】2.2 模型与材质空间

Tip of edge browser: enter+ctrl can automatically convert the address bar into a web address

Embedded System Development Notes 79: why should I get the IP address of the local network card

MFC window scroll bar usage
随机推荐
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis
Account sharing technology enables the farmers' market and reshapes the efficiency of transaction management services
LeetCode 1380. Lucky number in matrix
Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security
嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
This may be your last chance to join Tencent
程序员女友给我做了一个疲劳驾驶检测
674. longest continuous increasing sequence force buckle JS
10. regular expression matching
[TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
Unexpected token o in JSON at position 1, JSON parsing problem
基于Unet的环路滤波
Leetcode learning - day 36
Go learning --- unit test subtest
JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction
[JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
[EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)