이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
struct tree {
int pot;
vector<int> T;
void init(int N) {
pot = 1;
while(pot < N) pot <<= 1;
for(int i = 0;i < pot * 2;i++) T.pb(0);
}
void add(int x) {
x += pot;
T[x]++;
x >>= 1;
while(x > 0) T[x] = T[x * 2] + T[x * 2 + 1], x >>= 1;
}
int find(int x, int lo, int hi, int target) {
if(lo == hi) return lo;
int mid = (lo + hi) / 2;
if(T[x * 2] >= target)
return find(x * 2, lo, mid, target);
else
return find(x * 2 + 1, mid + 1, hi, target - T[x * 2]);
}
ii medians() {
int K = T[1];
int p1 = (K - 1) / 2 + 1;
int p2 = K / 2 + 1;
return {find(1, 0, pot - 1, p1), find(1, 0, pot - 1, p2)};
}
};
int sequence(int N, vector<int> A) {
tree T;
T.init(N);
for(int i = 0;i < N;i++) A[i]--;
int ans = 0;
for(int i = 0;i < N;i++) {
vector<int> cnt(N, 0);
tree T;
T.init(N);
for(int j = i;j < N;j++) {
cnt[A[j]]++;
T.add(A[j]);
ii p = T.medians();
ans = max(ans, max(cnt[p.x], cnt[p.y]));
}
}
return 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... |