이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
const int N = 2050;
int cnt[N];
int tree[N * 4 + 512];
void add(int node, int cl, int cr, int id){
tree[node] ++ ;
if(cl == cr){
return;
}
int mid = (cl + cr) / 2;
if(mid >= id)
add(node * 2, cl, mid, id);
else
add(node * 2 + 1, mid + 1, cr, id);
}
int find_idx(int node, int cl, int cr, int lim){
if(cl == cr) {
return tree[node];
}
int mid = (cl + cr) / 2;
if(tree[node * 2] >= lim){
return find_idx(node * 2, cl, mid, lim);
}
else{
return find_idx(node * 2 + 1, mid + 1, cr, lim - tree[node * 2]);
}
}
void init(int node, int cl, int cr){
tree[node] = 0;
if(cl == cr) return;
int mid = (cl + cr) / 2;
init(node * 2, cl, mid);
init(node * 2 + 1, mid + 1, cr);
}
int sequence(int n, vector<int> a) {
int ans = 0;
int sz;
int me;
for(int i = 0 ; i < n; i ++) {
init(1, 1, n);
for(int j = i ; j < n; j ++) {
add(1, 1, n, a[j]);
sz = j - i + 1;
if(sz % 2 == 1){
me = (sz + 1) / 2;
ans = max(ans, find_idx(1, 1, n, me));
}
else{
me = (sz + 1) / 2;
ans = max(ans, find_idx(1, 1, n, me));
ans = max(ans, find_idx(1, 1, n, me + 1));
}
}
}
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... |