对100%数据有1<=Li<=Ri<=N<=200000,1<=M<=200000
#include<cstdio> #include<algorithm> #include<cmath> #include<iostream> #define inf 0x3f3f3f3f #define LL unsigned long long #define lson u<<1,l,mid #define rson u<<1|1,mid+1,r #define maxn 200000 using namespace std; struct node{ int s; }e[4*maxn+1]; int n,m; void build(int u,int l,int r) { e[u].s=r-l+1; if(l==r)return; int mid=(l+r)>>1; build(lson); build(rson); } void update(int u,int l,int r,int x,int y) { if(e[u].s==0)return ; if(x<=l&&y>=r) { e[u].s=0; return ; } int mid = (l+r)>>1; if(x<=mid)update(lson,x,y); if(mid<y)update(rson,x,y); e[u].s=e[u<<1].s+e[u<<1|1].s; } /******Program Begin*********/ int main() { scanf("%d",&n); build(1,1,n); scanf("%d",&m); int x,y; for(int i=1;i<=m;i++) { scanf("%d%d",&x,&y); update(1,1,n,x,y); printf("%d\n",e[1].s); } return 0; } /*******Program End**********/