This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
const int M = 5003;
int tree[M];
inline void upd(int i, int v) {
i++;
while (i < M) {
tree[i] += v;
i += i & -i;
}
}
inline int get(int v) {
int pos = 0, sum = 0;
for (int i = 12; i >= 0; --i) {
if (pos + (1 << i) < M && sum + tree[pos + (1 << i)] < v) {
pos += 1 << i;
sum += tree[pos];
}
}
return pos;
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
int ret = 0, best = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
upd(j, 1);
}
int tmp = 0;
for (int j = 0; j < C; ++j) {
vector<int> ppl;
for (int k = 0; k < E[j] - S[j] + 1; ++k) {
int f = get(S[j] + 1 + k);
ppl.push_back(f);
}
int mx = 0;
for (int k : ppl) {
mx = max(mx, (k == i ? R : (k < i ? K[k] : K[k - 1])));
}
for (int k : ppl) {
int val = (k == i ? R : (k < i ? K[k] : K[k - 1]));
if (val != mx) {
upd(k, -1);
} else if (k == i) {
tmp++;
}
}
}
int x = get(1);
upd(x, -1);
if (tmp > best) {
best = tmp;
ret = i;
}
}
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |