이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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>;
struct MedianDS {
multiset <ll, greater <ll> > st1; // big to small (mid...0)
multiset <ll> st2; // small to big (mid...n)
MedianDS () {}
void stabilize () {
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());
}
}
void insert (ll x) {
ll mid = (st2.size() ? *st2.begin() : 0);
if (x >= mid) st2.insert(x);
else st1.insert(x);
stabilize();
}
void erase (ll x) {
ll mid = (st2.size() ? *st2.begin() : 0);
if (x >= mid) st2.erase(st2.find(x));
else st1.erase(st1.find(x));
stabilize();
}
pair <ll, ll> query () {
if (st1.size() == st2.size()) { // two medians
ll med1 = *st1.begin();
ll med2 = *st2.begin();
return { med1, med2 };
} else { // one median
assert(st2.size() > st1.size());
ll med = *st2.begin();
return { med, med };
}
}
};
int sequence (int n, vi ve) {
for (int &i : ve) i--;
ll ans = 0;
for (ll l = 0; l < n; l++) {
vll freq(n, 0);
MedianDS ds;
for (ll r = l; r < n; r++) {
freq[ve[r]]++;
ds.insert(ve[r]);
auto [a, b] = ds.query();
ans = max(ans, freq[a]);
ans = max(ans, freq[b]);
}
}
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... |