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