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 "prize.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> mem[200000];
vector<int> Ask(int i)
{
if (mem[i].size()) return mem[i];
return mem[i] = ask(i);
}
int find_best(int n)
{
int i = 0;
vector<int> cur = Ask(i);
for (int j = 0; j < n && j < 500; j++)
{
vector<int> res = Ask(j);
if (res[0] + res[1] == 0)
return j;
if (res[0] + res[1] > cur[0] + cur[1])
i = j, cur = res;
}
while (i < n)
{
for (int j = 18; j >= 0; j--)
if (i + (1 << j) < n)
{
vector<int> res = Ask(i + (1 << j));
if (res[0] == cur[0] && res[1] == cur[1])
i += (1 << j);
}
while (i < n)
{
vector<int> res = Ask(++i);
if (res[0] + res[1] == 0) return i;
if (cur[0] + cur[1] == res[0] + res[1])
{
cur = res;
break;
}
}
}
return n - 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |