이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include <vector>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
int sequence(int N, vector<int> A) {
vector<unordered_map<int, int>> prefixFreq(N + 1);
for (int i = 0; i < N; ++i) {
prefixFreq[i + 1] = prefixFreq[i];
prefixFreq[i + 1][A[i]]++;
}
int maxOccurrences = 0;
for (int l = 0; l < N; ++l) {
multiset<int> leftSet, rightSet;
unordered_map<int, int> freq;
for (int r = l; r < N; ++r) {
if (leftSet.empty() || A[r] <= *leftSet.rbegin()) {
leftSet.insert(A[r]);
} else {
rightSet.insert(A[r]);
}
while (leftSet.size() > rightSet.size() + 1) {
rightSet.insert(*leftSet.rbegin());
leftSet.erase(prev(leftSet.end()));
}
while (rightSet.size() > leftSet.size()) {
leftSet.insert(*rightSet.begin());
rightSet.erase(rightSet.begin());
}
int median1 = *leftSet.rbegin();
int median2 = (leftSet.size() + rightSet.size()) % 2 == 0 ? *rightSet.begin() : median1;
freq[A[r]]++;
maxOccurrences = max(maxOccurrences, freq[median1]);
if (median1 != median2) {
maxOccurrences = max(maxOccurrences, freq[median2]);
}
}
}
return maxOccurrences;
}
# | 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... |