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/extc++.h>
using namespace std;
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
__gnu_cxx::rope<int> r;
vector<int> ans(N+1),cl(N),cr(N),lp(N),rp(N);
int cnt = 0;
for (int i = 0; i < N-1; i++) if (K[i] > R) {
cl[i+1]++;
cr[i]++;
cnt++;
}
for (int i = 1; i < N; i++) cl[i]+=cl[i-1];
for (int i = N-2; i >= 0; i--) cr[i]+=cr[i+1];
for (int i = 0; i < N; i++) {
lp[i]=rp[i]=i;
r.push_back(i);
}
for (int i = 0; i < C; i++) {
int j = lp.size();
lp.push_back(lp[r[S[i]]]);
rp.push_back(rp[r[E[i]]]);
r.erase(S[i],E[i]-S[i]+1);
r.insert(S[i],j);
if (cl[lp[j]]+cr[rp[j]]==cnt) ans[lp[j]]++,ans[rp[j]+1]--;
}
for (int i = 1; i <= N; i++) ans[i] += ans[i-1];
return max_element(ans.begin(),ans.begin()+N)-ans.begin();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |