#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
// <|°_°|>
const int INFINI = (1000 * 1000 * 1000);
const int MAX_CHEVALIERS = (100 * 1000);
const int LOG = (16);
int NbVictoires[MAX_CHEVALIERS];
int Rang[MAX_CHEVALIERS];
int Next[MAX_CHEVALIERS];
int Fenwick[MAX_CHEVALIERS];
int FindNext(int a) {
if (Rang[Next[a]] >= 0)
return Next[a];
return Next[a] = FindNext(Next[a]);
}
void Add(int id, int val) {
for (int i = id; i < MAX_CHEVALIERS; i |= (i + 1))
{
Fenwick[i] += val;
}
return;
}
int FindFirst(int nb) {
int ans = -1;
int sum = 0;
for (int i = (1 << LOG); i > 0; i >>= 1)
{
if (ans + i < MAX_CHEVALIERS && sum + Fenwick[ans + i] < nb)
{
ans += i;
sum += Fenwick[ans];
}
}
return ans + 1;
}
int GetBestPosition(int nbChevaliers, int nbRounds, int nouvRang, int *Ranks, int *Left, int *Right) {
for (int i = 0; i < nbChevaliers; i ++)
{
Next[i] = i + 1;
Rang[i] = Ranks[i];
NbVictoires[i] = 0;
Add(i, 1);
}
pair <int, int> ans = {0, 0};
for (int i = 0; i < nbRounds; i ++)
{
Left[i] ++, Right[i] ++;
vector <int> pos;
/*for (int j = Left[i]; j <= Right[i]; j ++)
{
pos.push_back(FindFirst(j));
}*/
int first = FindFirst(Left[i]);
for (int c = Left[i]; c <= Right[i]; c ++)
{
pos.push_back(first);
first = FindNext(first);
}
int maxRang = -1;
pair <int, int> maxDP = {- INFINI - 1, 0};
for (int a : pos)
{
if (a != pos.back())
maxRang = max(maxRang, Rang[a]);
if (NbVictoires[a] > maxDP.first)
maxDP = {NbVictoires[a], a};
}
maxDP.first ++;
if (maxRang > nouvRang)
maxDP.first = - INFINI;
Rang[maxDP.second] = max(maxRang, Rang[pos.back()]);
NbVictoires[maxDP.second] = maxDP.first;
for (int a : pos)
{
if (a != maxDP.second)
{
Rang[a] = -1;
Add(a, -1);
NbVictoires[a] = - INFINI;
}
}
if (maxDP.first > ans.first || (maxDP.first == ans.first && maxDP.second < ans.second))
{
ans = make_pair(maxDP.first, maxDP.second);
}
}
return ans.second;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
4 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
572 KB |
Output is correct |
10 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1464 KB |
Output is correct |
2 |
Correct |
61 ms |
4424 KB |
Output is correct |
3 |
Correct |
29 ms |
4444 KB |
Output is correct |
4 |
Correct |
54 ms |
3868 KB |
Output is correct |
5 |
Correct |
64 ms |
3684 KB |
Output is correct |
6 |
Correct |
47 ms |
3572 KB |
Output is correct |
7 |
Correct |
62 ms |
3912 KB |
Output is correct |
8 |
Correct |
56 ms |
4076 KB |
Output is correct |
9 |
Correct |
21 ms |
4216 KB |
Output is correct |
10 |
Correct |
23 ms |
2836 KB |
Output is correct |