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;
using ll = long long;
using vll = vector <ll>;
using vi = vector <int>;
using ii = pair <ll, ll>;
using vii = vector <ii>;
int sequence (int n, vi ve) {
for (int &i : ve) i--;
ll ans = 0;
for (ll l = 0; l < n; l++) {
multiset <ll, greater <ll> > st1; // big to small (mid...0)
multiset <ll> st2; // small to big (mid...n)
vll freq(n, 0);
for (ll r = l; r < n; r++) {
ll mid = (st2.size() ? *st2.begin() : 0);
freq[ve[r]]++;
if (ve[r] >= mid) st2.insert(ve[r]);
else st1.insert(ve[r]);
while (st2.size() > st1.size()) {
st1.insert(*st2.begin());
st2.erase(st2.begin());
}
while (st1.size() > st2.size()) {
st2.insert(*st1.begin());
st1.erase(st1.begin());
}
if (st1.size() == st2.size()) { // two medians
ll med1 = *st1.begin();
ll med2 = *st2.begin();
ans = max(ans, freq[med1]);
ans = max(ans, freq[med2]);
} else { // one median
assert(st2.size() > st1.size());
ll med = *st2.begin();
ans = max(ans, freq[med]);
}
}
}
return int(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... |