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 MAXN = 1e5 + 10;
int st[17][MAXN];
int query(int l, int r) {
int k = 32 - __builtin_clz(r-l+1) - 1; return max(st[k][l], st[k][r - (1<<k) + 1]);
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
int og[C];
for(int i=0; i<C; i++) og[i] = E[i] - S[i];
for(int i=0; i<C; i++) {
for(int j=i+1; j<C; j++) {
if(S[j] > S[i]) S[j] += og[i];
if(E[j] >= S[i]) E[j] += og[i];
}
}
int opt_cnt = 0, opt_id = -1;
for(int P=0; P<N; P++) {
vector<int> now;
for(int j=0; j<P; j++) now.push_back(K[j]);
now.push_back(R);
for(int j=P; j<N; j++) now.push_back(K[j]);
for(int j=0; j<N; j++) st[0][j] = now[j];
for(int j=1; j<17; j++) {
for(int k=0; k<N; k++) {
if(k + (1<<j) - 1 < N) {
st[j][k] = max(st[j-1][k], st[j-1][k + (1 << (j-1))]);
}
}
}
int ok = 0;
for(int j=0; j<C; j++) {
ok += (query(S[j], E[j]) == R);
}
if(ok > opt_cnt) {
opt_cnt = ok;
opt_id = P;
}
}
return opt_id;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |