- Title Description Description
There are N points on a line axis, respectively, 1~n. At first all the dots were dyed black. Then
We carry out m operations, and the first operation will [Li,ri] these dianran into white. Please output each operation after execution
The number of black dots remaining.
- Enter a description input Description
Enter a behavior of N and M. The following m lines are two numbers per line Li, Ri
- Outputs description output Description
Output m line, the number of black points remaining after each operation.
10 3
3 3
5 7
2 8
- Sample output sample outputs
9
6
3
Data limitations
1<=n<=2000,1<=m<=2000 for 30% of the data
1<=li<=ri<=n<=200000,1<=m<=200000 for 100% data
#include <iostream>#include<cstdio>using namespacestd;intsum,tot=0;structtreetype{intLeft,right;//interval [left,right] intLptr,rptr;//child hands left and right intSum//intervals and intbj//Mark}t[2000000];voidBuildtree (intllintRR) { intcur=++tot; T[cur]. Left=ll; T[cur]. right=RR; if(ll!=rr-1) {t[cur].lptr=tot+1; Buildtree (LL, LL+RR)/2); T[cur].rptr=tot+1; Buildtree (+ (LL+RR)/2, RR); T[cur].sum=t[t[cur].lptr].sum+t[t[cur].rptr].sum; }Elset[cur].sum=1;}voidUpdateintK//delay message Next pass{t[t[k].lptr].sum=0; t[t[k].rptr].sum=0;//empty left and right sub-ranget[t[k].lptr].bj=1; t[t[k].rptr].bj=1;//Pass Flagt[k].bj=0;//Clear Flag}voidChangeintKintllintRr//Modifying the value of an interval [LL,RR] element{ if(Ll<=t[k]. LEFT&&RR>=T[K]. right)//Overwrite current interval{t[k].sum=0;//intervals and =0t[k].bj=1;//Set logo } Else { if(T[K].BJ) update (k);//Pass Modification if(ll< (t[k). LEFT+T[K]. right)/2)//Modify left IntervalChange (T[K].LPTR,LL,RR); if(Rr> (t[k). LEFT+T[K]. right)/2)//Modify Right IntervalChange (T[K].RPTR,LL,RR); T[k].sum=t[t[k].lptr].sum+t[t[k].rptr].sum;//update intervals and }}intQueryintKintllintRr//query [LL,RR] interval and{ if(Ll<=t[k]. LEFT&&RR>=T[K]. right)returnt[k].sum; if(T[K].BJ) update (k);//Pass Modification intans=0; if(ll< (t[k). LEFT+T[K]. right)/2) ans+=query (T[K].LPTR,LL,RR); if(Rr> (t[k). LEFT+T[K]. right)/2) ans+=query (T[K].RPTR,LL,RR); returnans;}intMain () {intN,tim,x,y; scanf ("%d%d",&n,&Tim); Sum=N; Buildtree (1, n+1); for(intI=1; i<=tim;i++) {scanf ("%d%d",&x,&y); Change (1, x,y+1); printf ("%d\n", Query (1,1, n+1)); } return 0;}
"CODEVS1191" axis dyeing