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