Submission #966839

#TimeUsernameProblemLanguageResultExecution timeMemory
966839Batorgil952Sequence (APIO23_sequence)C++17
0 / 100
2028 ms15688 KiB
#include "sequence.h" #include<bits/stdc++.h> #include <vector> using namespace std; const int N=5e5+5; int T[N]; int sequence(int N, std::vector<int> A) { int sn, pn, ans; if(N<=2000){ for(int i=0; i<=N; i++){ T[i]=0; } ans=1; for(int i=0; i<N; i++){ multiset< int > S, P; multiset< int > :: iterator it, ip; sn=1; pn=0; S.insert(A[i]); T[A[i]]++; for(int j=i+1; j<N; j++){ T[A[j]]++; if(pn==0){ pn++; it=S.begin(); if(A[j]<(*it)){ P.insert(*it); S.erase(it); S.insert(A[j]); } else{ P.insert(A[j]); } ans=max(ans, T[A[j]]); } else{ it=S.end(); it--; if((*it)>=A[j]){ S.insert(A[j]); sn++; } else{ P.insert(A[j]); pn++; } if(sn>=pn+2){ it=S.begin(); P.insert(*it); S.erase(it); } if(pn>=sn+2){ it=P.begin(); S.insert(*it); P.erase(it); } it=S.end(); it--; ip=P.begin(); if((sn+pn)%2==0){ ans=max(ans, max(T[*it], T[*ip])); } else{ ans=max(ans, T[*it]); } } } for(int j=i; j<N; j++){ T[A[j]]=0; } } return ans; } }

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
   79 | }
      | ^
#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...