# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
966839 | Batorgil952 | Sequence (APIO23_sequence) | C++17 | 2028 ms | 15688 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |