Meaning of the questions: given n, c, k.
Then gives the n numbers (between 1 ~ c), Q longest interval length. The section numbers that satisfy any occurrence of k appears at least once.
Ideas:
we can probably meet the criteria to judge the interval, and then press the interval does not meet the index number of conditions for inter-partition again, to judge again.
Until all possible to meet the conditions of the interval are judged finished.
: Pit
under the subject of the relationship between the number of paying particular attention in the inter-partition, for treatment of more complicated boundary, (l, r) and the conditions are not satisfied.
: Pit
under the subject of the relationship between the number of paying particular attention in the inter-partition, for treatment of more complicated boundary, (l, r) and the conditions are not satisfied.
#include<bits/stdc++.h> using namespace std; #define met(a,b) memset(a,b,sizeof(a)) int a[100009]; int ans=0; map<int, vector<int> >pos; int n,c,k; void dfs(int l,int r) { //cout<<l<<"............."<<r<<endl; if(r-l+1<k) return; if(l==r) { if(k<=1)ans=max(ans,1); return ; } else if(r<l) return ; int i=0; for( i=l; i<=r; i++){ int tl=lower_bound(pos[a[i]].begin(),pos[a[i]].end(),l)-pos[a[i]].begin(); int tr=upper_bound(pos[a[i]].begin(),pos[a[i]].end(),r)-pos[a[i]].begin(); if(tr-tl<k) break; } if(i==r+1) ans=max(ans,r-l+1); else { int st=l,j; for(j=0;j<pos[a[i]].size();j++)if(st<=pos[a[i]][j])break; for(;j<pos[a[i]].size()&&pos[a[i]][j]<r;j++) { dfs(st,pos[a[i]][j]-1); st=pos[a[i]][j]+1; } if(j<pos[a[i]].size()) dfs(st,r); else { dfs(pos[a[i]][j-1]+1,r); } } return ; } int main() { while(cin>>n>>c>>k) { for(int i=1;i<=c;i++)pos[i].clear(); met(a,0); ans=0; for(int i=1; i<=n; i++) { scanf("%d",&a[i]); pos[a[i]].push_back(i); } // cout<<"1"<<" "<<n<<endl; dfs(1,n); cost<<ans<<endl; } return 0; }