1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include<iostream> #include<cstdio> #include<vector> using namespace std; long long read() { long long x=0,f=1; char c=getchar(); while(!isdigit(c)){if(c=='-') f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } const int N=100000+100; int ans,tot[N]; struct SegmentTree { #define lson (now<<1) #define rson (now<<11) #define mid ((now_l+now_r)/2) vector <int> son[N<<2]; int IsClear[N<<2],cnt[N]; inline void update(int now) { IsClear[now]=IsClear[lson]&IsClear[rson]; } void Mark(int L,int R,int x,int now,int now_l,int now_r) { if(now_l>=L and now_r<=R) { tot[x]++; son[now].push_back(x); return; } if(L<=mid) Mark(L,R,x,lson,now_l,mid); if(R>mid) Mark(L,R,x,rson,mid+1,now_r); } void Sub(int x,int now,int now_l,int now_r) { if(now_l==now_r) { cnt[x]--; if(cnt[x]==0) IsClear[now]=true; } if(now_l!=now_r) { if(x<=mid) Sub(x,lson,now_l,mid); else Sub(x,rson,mid+1,now_r); update(now); } if(IsClear[now]==true) for(int i=0;i<int(son[now].size());i++) { tot[son[now][i]]--; if(tot[son[now][i]]==0) ans++; } } #undef lson #undef rson #undef mid }sgt; int n,m,q; int main() { n=read(),m=read(); for(int i=1;i<=n;i++) sgt.cnt[i]=read(); for(int i=1;i<=m;i++) { int L=read(),R=read(); sgt.Mark(L,R,i,1,1,n); }
int q=read(),lans=0; for(int i=1;i<=q;i++) { int x=read(); x=(x+lans-1)%n+1; sgt.Sub(x,1,1,n); lans=ans; printf("%d\n",lans); } return 0; }
|