Submission #982554

#TimeUsernameProblemLanguageResultExecution timeMemory
982554GhettoSequence (APIO23_sequence)C++17
11 / 100
2097 ms54328 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5 + 5; int n; int a[MAX_N]; int sequence(int tmp_n, vector<int> tmp_a) { n = tmp_n; for (int i = 0; i < n; i++) a[i + 1] = tmp_a[i]; int ans = 0; for (int l = 1; l <= n; l++) { unordered_map<int, int> freq; multiset<int> smalls, bigs; for (int r = l; r <= n; r++) { freq[a[r]]++; if (smalls.empty() || a[r] <= *smalls.rbegin()) smalls.insert(a[r]); else bigs.insert(a[r]); while (bigs.size() > smalls.size()) smalls.insert(*bigs.begin()), bigs.erase(bigs.begin()); while (smalls.size() > bigs.size() + 1) bigs.insert(*smalls.rbegin()), smalls.erase(next(smalls.end(), -1)); vector<int> medians = {*smalls.rbegin()}; if (bigs.size()) medians.push_back(*bigs.begin()); for (int x : medians) ans = max(ans, freq[x]); } } 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...