2019 Multi-University Training Contest 2
Posted dongdong25800
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2019 Multi-University Training Contest 2相关的知识,希望对你有一定的参考价值。
Longest Subarray
#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的主要内容,如果未能解决你的问题,请参考以下文章
2019 Multi-University Training Contest 6
2019 Multi-University Training Contest 6
2019 Multi-University Training Contest 6
2019 Multi-University Training Contest 3