time limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle 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
Output description
Output Description
Output m line, the number of black points remaining after each operation.
Sample input
Sample Input
10 3
3 3
5 7
2 8
Sample output
Sample Output
9
6
3
Data range and Tips
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
Portal Segment Tree (interval modification).
#include <iostream>#include<cstring>#include<cstdio>using namespacestd;inti,j,n,m,li,ri,s,tr[200000*4+1];inlinevoidBuildintllintRrintNow ) { if(ll==RR) {Tr[now]=1; return; } intM= (LL+RR)/2; Build (Ll,m,now*2); Build (M+1, rr,now*2+1); Tr[now]=tr[now*2]+tr[now*2+1];} InlinevoidRsintllintRrintNow ) { if(ll>ri| | rr<li| | tr[now]==0)return; if(ll>=li&&rr<=RI) {Tr[now]=0; return; } intMid= (LL+RR)/2; RS (Ll,mid,now*2); RS (Mid+1, rr,now*2+1); Tr[now]=tr[now*2]+tr[now*2+1]; return;}intMain () {CIN>>n>>m; Build (1N1); for(i=0; i<m;++i) {cin>>li>>RI; RS (1N1); printf ("%d\n", tr[1]); }}
Codevs 1191 Axis Dyeing