Submission #855427

#TimeUsernameProblemLanguageResultExecution timeMemory
855427MilosMilutinovicSequence (APIO23_sequence)C++17
11 / 100
2061 ms152668 KiB
#include "sequence.h" #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> pii; int readint(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } const int N=5000500; int n,a[N],val[N],pref[N]; vector<int> pos[N]; int sequence(int N,vector<int> A) { n=N; for(int i=1;i<=n;i++) a[i]=A[i-1]; for(int i=1;i<=n;i++) pos[a[i]].pb(i); //build(1,1,n); for(int i=1;i<=n;i++) val[i]=1; int ans=0; for(int v=1;v<=n;v++){ if(pos[v].empty()) continue; for(int j:pos[v]) val[j]=0; // for(int j:pos[v]) modify(1,1,n,j,n,-1); for(int i=1;i<=n;i++) pref[i]=pref[i-1]+val[i]; for(int l=1;l<=n;l++){ int cnt=0; for(int r=l;r<=n;r++){ cnt+=(a[r]==v?1:0); if(abs(pref[r]-pref[l-1])<=cnt) ans=max(ans,cnt); } } // for(int j:pos[v]) modify(1,1,n,j,n,-1); for(int j:pos[v]) val[j]=-1; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...