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
| #include<iostream> #include<array> #include<algorithm> #include<cmath> using namespace std; using gg=int; struct node{ gg l,r; }zero; array<node,400010> tree,tag; gg n,m; void pushdown(const gg &p) { if(tag[p].l) { tag[p*2]=tag[p*2+1]=tree[p*2]=tree[p*2+1]=tag[p]; tag[p]=zero; } return; } void build(const gg &l,const gg &r,const gg &p) { if(l==r) { tree[p].l=1; tree[p].r=n; return; } gg mid=(l+r)/2; build(l,mid,p*2); build(mid+1,r,p*2+1); return; } void update(const gg &l,const gg &r,const gg &nl,const gg &nr,const gg &p,const node &k) { if(nl>=l&&nr<=r) { tree[p]=tag[p]=k; return; } pushdown(p); gg mid=(nl+nr)/2; if(mid>=l) { update(l,r,nl,mid,p*2,k); } if(mid+1<=r) { update(l,r,mid+1,nr,p*2+1,k); } return; } node getpoi(const gg &x,const gg &nl,const gg &nr,const gg &p) { if(nl==nr) { return tree[p]; } pushdown(p); gg mid=(nl+nr)/2; if(mid>=x) return getpoi(x,nl,mid,p*2); else return getpoi(x,mid+1,nr,p*2+1); } int main() { ios::sync_with_stdio(false); cin.tie(0); gg x; cin>>n>>m; build(1,n,1); while(m--) { cin>>x; node ll=getpoi(x,1,n,1),rr=getpoi(x+1,1,n,1); if(ll.l!=rr.l&&ll.r!=rr.r) { cout<<0<<'\n'; } else { cout<<(x-ll.l+1)*(rr.r-x)<<'\n'; update(ll.l,x,1,n,1,{ll.l,x}); update(x+1,rr.r,1,n,1,{x+1,rr.r}); } } return 0; }
|