제출 #855654

#제출 시각아이디문제언어결과실행 시간메모리
855654MilosMilutinovic서열 (APIO23_sequence)C++17
0 / 100
2045 ms149228 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; } int n,a[5000500],val[5000500],pref[5000500]; vector<int> pos[5000500]; int query_mn(int l,int r){ int mn=1e9; for(int i=l;i<=r;i++) mn=min(mn,pref[i]); return mn; } int query_mx(int l,int r){ int mx=-1e9; for(int i=l;i<=r;i++) mx=max(mx,pref[i]); return mx; } int min_diff(int l1,int r1,int l2,int r2){ if(max(l1,l2)<=min(r1,r2)) return 0; return min(abs(l1-r2),abs(l2-r1)); } bool good(int l,int r,int c){ return min_diff(query_mn(0,l),query_mx(0,l),query_mn(r,n),query_mx(r,n))<=c; } 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]--; for(int i=1;i<=n;i++) pref[i]=pref[i-1]+val[i]; int sz=(int)pos[v].size(); int ptr=0; for(int i=0;i<sz;i++){ while(ptr<sz&&good(pos[v][i],pos[v][ptr],ptr-i+1)) ptr++; ans=max(ans,ptr-i); } for(int j:pos[v]) val[j]--; } 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...