# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1063434 |
2024-08-17T18:30:16 Z |
fv3 |
The Big Prize (IOI17_prize) |
C++14 |
|
61 ms |
4440 KB |
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> st;
int nt = 1;
int get_offset(int i, int k, int x, int y)
{
if (x > i) return 0;
if (y <= i) return st[k];
int c = (x + y) / 2;
return get_offset(i, k*2, x, c) + get_offset(i, k*2|1, c+1, y);
}
void add(int index)
{
st[nt + index] = 1;
for (int i = (nt + index) / 2; i >= 1; i /= 2)
st[i] = st[i*2] + st[i*2|1];
}
int prize_pos = 0;
bool attempt(int &mx_cnt)
{
st = vector<int>(2 * nt);
cerr << "mx_cnt = " << mx_cnt << '\n';
for (int q = 0; 1; q++)
{
int l = 0, r = N - 1;
while (l < r)
{
int c = (l + r) / 2;
int index = c + get_offset(c, 1, 0, nt - 1);
auto val = ask(index);
int cnt = val[0] + val[1];
if (cnt == 0)
{
prize_pos = index;
return true;
}
if (cnt < mx_cnt)
{
add(index);
r--;
continue;
}
if (cnt > mx_cnt)
{
mx_cnt = cnt;
return false;
}
if (val[0] <= q)
l = c + 1;
else
r = c - 1;
}
int index = l + get_offset(l, 1, 0, nt - 1);
auto val = ask(index);
int cnt = val[0] + val[1];
if (cnt == 0)
{
prize_pos = index;
return true;
}
add(index);
}
return true;
}
int find_best(int n)
{
N = n;
while (nt < N) nt <<= 1;
st = vector<int>(2 * nt);
int mx_cnt = 2;
while (!attempt(mx_cnt));
return prize_pos;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
4440 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
61 ms |
4440 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |