이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = (1 << 18);
int nDebuts[N * 2];
int cumul[N];
bool onGagne(int fin, int deb){
int sum = cumul[fin];
if (deb > 0)
sum -= cumul[deb - 1];
return (sum == 0);
}
int getSum(int gauche, int droite){
if (gauche > droite)
return 0;
if (gauche%2 == 1)
return nDebuts[gauche] + getSum(gauche + 1, droite);
if (droite%2 == 0)
return nDebuts[droite] + getSum(gauche, droite - 1);
return getSum(gauche / 2, droite / 2);
}
int GetBestPosition(int nGars, int nRounds, int rangPaume, int *rangs, int *gauche, int *droite) {
for (int iRound = 0; iRound < nRounds; ++iRound){
int compression = droite[iRound] - gauche[iRound];
gauche[iRound] += getSum(N, N + gauche[iRound] - 1);
droite[iRound] += getSum(N, N + droite[iRound]);
for (int noeud = N + gauche[iRound]; noeud > 0; noeud /= 2)
nDebuts[noeud] += compression;
}
for (int ind = 0; ind < nGars - 1; ++ind){
cumul[ind] = (rangs[ind] > rangPaume);
if (ind != 0)
cumul[ind] += cumul[ind - 1];
}
for (int iRound = 0; iRound < nRounds; ++iRound){
if (onGagne(gauche[iRound], droite[iRound])){
cumul[gauche[iRound]]++;
cumul[droite[iRound]]--;
}
}
int iOpt = 0;
for (int ind = 1; ind < nGars; ++ind){
cumul[ind] += cumul[ind - 1];
if (cumul[ind] > cumul[iOpt])
iOpt = ind;
}
return iOpt;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |