标签:lap span contest ide turn upd play += push
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; vector<int> v[maxn]; int n,k,c; struct note { int left,right,maxx,lazy,ans; void up(int val) { maxx+=val; lazy+=val; } } tree[maxn*4]; void pushup(int id) { tree[id].maxx=max(tree[id<<1].maxx,tree[id<<1|1].maxx); if(tree[id].maxx==tree[id<<1].maxx) tree[id].ans=tree[id<<1].ans; else tree[id].ans=tree[id<<1|1].ans; } void pushdown(int id) { if(tree[id].lazy) { tree[id<<1].up(tree[id].lazy); tree[id<<1|1].up(tree[id].lazy); tree[id].lazy=0; } } void build(int id,int l,int r) { tree[id].left=tree[id].ans=l; tree[id].right=r; tree[id].maxx=tree[id].lazy=0; if(l==r) return; int mid=(l+r)/2; build(id<<1,l,mid); build(id<<1|1,mid+1,r); pushup(id); } int query(int id,int l,int r) { if(tree[id].maxx!=c) return -1; if(l<=tree[id].left&&tree[id].right<=r) return tree[id].ans; pushdown(id); int mid=(tree[id].left+tree[id].right)/2; if(r<=mid) return query(id<<1,l,r); else if(l>mid) return query(id<<1|1,l,r); else { int tmp; tmp=query(id<<1,l,mid); if(tmp!=-1) return tmp; else return query(id<<1|1,mid+1,r); } } void update(int id,int l,int r,int val) { if(l<=tree[id].left&&tree[id].right<=r) { tree[id].up(val); return; } pushdown(id); int mid=(tree[id].left+tree[id].right)/2; if(l<=mid) update(id<<1,l,r,val); if(r>mid) update(id<<1|1,l,r,val); pushup(id); } int main() { while(~scanf("%d%d%d",&n,&c,&k)) { for(int i=1; i<=c; i++) { v[i].clear(); v[i].push_back(0); } build(1,1,n); int ans=0; for(int i=1; i<=n; i++) { int x; scanf("%d",&x); update(1,i,i,c-1); if(v[x].back()<i-1) update(1,v[x].back()+1,i-1,-1); v[x].push_back(i); if(v[x].size()>=k+1) { int pos=v[x].size()-k-1; update(1,v[x][pos]+1,v[x][pos+1],1); } int tmp=query(1,1,i); if(tmp!=-1) ans=max(ans,i-tmp+1); } printf("%d\n",ans); } }
2019 Multi-University Training Contest 2
标签:lap span contest ide turn upd play += push
原文地址:https://www.cnblogs.com/dongdong25800/p/11575187.html