Topic links: https://www.luogu.org/problem/P2161
The meaning of problems: there are two operations, the operation A is dyed in the interval l, r, while the number of output color overlapping with those of the case and air, B is the statistical operation section there are still many colors.
Analysis: to do with the tree line, used only to modify the interval, each time to find only one color range is modified, if the color has not been deleted, it counted and removed. Delete array can be directly used to achieve a del
#include <bits / STDC ++ H.> the using namespace STD; typedef Long Long LL; const int INF = 0x3f3f3f3f ; const int MOD = + 1E9 . 7 ; const int MAXN = + 2E5 . 7 ; #define LS << RT. 1 #define RS RT < <. 1 |. 1 int CNT = 0 ; // current number of color int ANS = 0 ; // this time is recorded how many colors int RES; // record the deletion of one a User how many colors struct Node { charopt [ 2 ]; int L, R & lt; } A [MAXN]; BOOL Same [MAXN << 2 ]; // representing whether within the same color range, a color is the same int Tag [MAXN << 2 ]; // the lazy tag recording the color BOOL del [MAXN]; // for whether a color marker is deleted void Build ( int RT, int L, int R & lt) { Same [RT] = . 1 ; tag [RT] = 0 ; iF (R & lt == L) return ; int MID = (L + R & lt) >> . 1 ; Build (LS, L, MID); Build (RS, MID +. 1 , R & lt); } void pushdown ( int L, int R & lt, int RT) { Same [RT] = 0 ; // key! ! ! ! // can pass under it shows a certain color is not the same IF (Tag [RT]!) Return ; // tag decentralized Tag [LS] Tag = [RS] = Tag [RT]; Tag [RT] = 0 ; } void Find ( int L, int R & lt, int RT) { IF (Same [RT] == . 1 ) { IF ! (del [Tag [RT]] && Tag [RT]) ANS -, RES ++; del[tag[rt]]=1; tag[rt]=cnt;//记录颜色 return; } int mid=(l+r)>>1; find(l,mid,ls);find(mid+1,r,rs); same[rt]=1;tag[rt]=cnt; } void modify(int l,int r,int s,int t,int rt){ if(s<=l&&r<=t){ find(l,r,rt); return ; } pushdown(l,r,rt); int mid=(l+r)>>1; if(s<=mid) modify(l,mid,s,t,ls); if(t>mid) modify(mid+1,r,s,t,rs); } int main(){ int n;scanf("%d",&n); int st=inf,ed=0;//记录左右端点 for(int i=1;i<=n;i++){ scanf("%s",a[i].opt); if(a[i].opt[0]=='A'){ scanf("%d%d",&a[i].l,&a[i].r); st=min(st,a[i].l);ed=max(ed,a[i].r); } } build(1,st,ed); for(int i=1;i<=n;i++){ if(a[i].opt[0]=='A'){ ++ans;++cnt;res=0; modify(st,ed,a[i].l,a[i].r,1); printf("%d\n",res); } else printf("%d\n",ans); } return 0; }