# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1062042 | KasymK | 서열 (APIO23_sequence) | C++17 | 2044 ms | 52168 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int sequence(int n, vector<int> v){
int answer = 0;
unordered_map<int, int> freq;
multiset<int> left, right;
auto add = [&](int x) {
freq[x]++;
if (!right.empty() && x >= *right.begin()) {
right.insert(x);
} else {
left.insert(x);
}
// Balance the left and right sets to maintain equal sizes
if (left.size() > right.size() + 1) {
right.insert(*left.rbegin());
left.erase(--left.end());
} else if (right.size() > left.size()) {
left.insert(*right.begin());
right.erase(right.begin());
}
};
auto remove = [&](int x) {
if (x >= *right.begin()) {
right.erase(right.find(x));
} else {
left.erase(left.find(x));
}
freq[x]--;
if (freq[x] == 0) freq.erase(x);
// Rebalance the sets
if (left.size() > right.size() + 1) {
right.insert(*left.rbegin());
left.erase(--left.end());
} else if (right.size() > left.size()) {
left.insert(*right.begin());
right.erase(right.begin());
}
};
for (int i = 0; i < n; ++i) {
left.clear();
right.clear();
freq.clear();
for (int j = i; j < n; ++j) {
add(v[j]);
int median1 = *left.rbegin();
int median2 = right.empty() ? median1 : *right.begin();
// Get the maximum frequency of median1 and median2
umax(answer, max(freq[median1], freq[median2]));
}
}
return answer;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |