Submission #760158

#TimeUsernameProblemLanguageResultExecution timeMemory
760158danikoynovSequence (APIO23_sequence)C++17
28 / 100
2078 ms29568 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int occ[maxn]; int sequence(int N, vector<int> A) { multiset < int > lf, rf; int ans = 1; for (int i = 0; i < N; i ++) { for (int j = 0; j <= N; j ++) occ[j] = 0; lf.clear(); rf.clear(); lf.insert(A[i]); occ[A[i]] ++; for (int j = i + 1; j < N; j ++) { occ[A[j]] ++; if (A[j] > *lf.rbegin()) rf.insert(A[j]); else lf.insert(A[j]); while(lf.size() > rf.size() + 1) { int x = *lf.rbegin(); lf.erase(lf.find(x)); rf.insert(x); } while(rf.size() > lf.size()) { int x = *rf.begin(); rf.erase(rf.find(x)); lf.insert(x); } if ((j - i + 1) % 2 == 0) { ans = max(ans, occ[*lf.rbegin()]); ans = max(ans, occ[*rf.begin()]); } else { ans = max(ans, occ[*lf.rbegin()]); } } } 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...