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.
sample input to sample
Ten 3
3 3
5 7
2 8
sample output Sample outputs
9
6
3
Data Size & Hint
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;intx,y,n,m;structtree{intL,r,v;} t[800001];voidBuildintNowintXinty) {T[NOW].L=x; T[now].r=y; if(x==y) {t[now].v=1;return; } intMid= (x+y) >>1; Build ( Now<<1, X,mid); Build ( Now<<1|1, mid+1, y); T[NOW].V=t[now<<1].v+t[now<<1|1].v; }voidChangeintKintXinty) { if(t[k].v==0)return; intL=t[k].l,r=T[K].R; if(L==x && r==y) {t[k].v=0;return; } intMid= (l+r) >>1; if(mid>=y) Change (k<<1, x, y); Else if(mid<x) Change (k<<1|1, x, y); Else{change (k<<1, X,mid); Change (k<<1|1, mid+1, y); } t[k].v=t[k<<1].v+t[k<<1|1].v;}intMain () {CIN>> N >>m; Build (1,1, N); for(intI=1; i<=m; i++) {cin>> x >>y; Change (1, x, y); printf ("%d\n", t[1].v); } return 0;}
codevs1191| Axis Dyeing | line tree