이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |