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>
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 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... |