#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> f[200005];
bool viz[200005];
vector<int> askk(int pos)
{
if (viz[pos])
return f[pos];
viz[pos] = true;
f[pos] = ask(pos - 1);
return f[pos];
}
/*
8
3 2 3 1 3 3 2 3
*/
int find_best(int n)
{
int sn = 2 * sqrt(n) + 1;
//int sn = 1;
sn = min(sn,n);
int nrmax = 0,ret_sc;
for (int i = 1; i <= sn; i++)
{
vector<int> cur = askk(i);
if (cur[0] + cur[1] == 0)
return i - 1;
nrmax = max(nrmax,cur[0] + cur[1]);
if (cur[0] + cur[1] == nrmax)
ret_sc = cur[1];
}
set<int> pozi;
int p = sn + 1;
while (true)
{
int st = p;
int dr;
if (pozi.empty() or ((*pozi.rbegin()) < p))
dr = n;
else
dr = *pozi.lower_bound(st);
while (st < dr)
{
int mij = (st + dr) / 2;
vector<int> cur = askk(mij);
if (cur[0] + cur[1] < nrmax)
pozi.insert(mij),dr = mij;
else
{
if (cur[1] == ret_sc)
st = mij + 1;
else
dr = mij;
}
}
while (true)
{
vector<int> cur = askk(st);
if (cur[0] + cur[1] == 0)
return st - 1;
st++;
p = st;
if (cur[0] + cur[1] == nrmax)
{
ret_sc = cur[1];
break;
}
}
}
}
///a[i] = tipul lui i, nu prea imi pasa cat e V dar ce stiu e ca sunt sub sqrt(N) a[i] < V
///o sa incerc sa le gasesc pe fiecare in parte si dau query in ele
///pai mai intai gasesc primul de tip V, apoi voi tot incerca sa gasesc primul de tip < V de dupa si apoi brut pana la urmatorul de tip V
///asta cu binara, sigur da 90 ca e sqrtlog dar poate mai mult
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:56:17: warning: 'ret_sc' may be used uninitialized in this function [-Wmaybe-uninitialized]
56 | if (cur[1] == ret_sc)
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5124 KB |
Output is correct |
2 |
Correct |
6 ms |
5128 KB |
Output is correct |
3 |
Correct |
6 ms |
5208 KB |
Output is correct |
4 |
Correct |
6 ms |
4952 KB |
Output is correct |
5 |
Correct |
6 ms |
5208 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
7 ms |
5148 KB |
Output is correct |
8 |
Correct |
7 ms |
5208 KB |
Output is correct |
9 |
Correct |
7 ms |
4952 KB |
Output is correct |
10 |
Correct |
8 ms |
5156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5168 KB |
Output is correct |
2 |
Correct |
8 ms |
5208 KB |
Output is correct |
3 |
Correct |
6 ms |
4952 KB |
Output is correct |
4 |
Correct |
8 ms |
5464 KB |
Output is correct |
5 |
Correct |
8 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
4952 KB |
Output is correct |
7 |
Correct |
6 ms |
4952 KB |
Output is correct |
8 |
Correct |
5 ms |
4952 KB |
Output is correct |
9 |
Correct |
6 ms |
4952 KB |
Output is correct |
10 |
Correct |
8 ms |
5152 KB |
Output is correct |
11 |
Correct |
7 ms |
5208 KB |
Output is correct |
12 |
Correct |
8 ms |
5208 KB |
Output is correct |
13 |
Correct |
9 ms |
5144 KB |
Output is correct |
14 |
Correct |
5 ms |
4952 KB |
Output is correct |
15 |
Correct |
14 ms |
5208 KB |
Output is correct |
16 |
Partially correct |
37 ms |
5712 KB |
Partially correct - number of queries: 7166 |
17 |
Correct |
4 ms |
4952 KB |
Output is correct |
18 |
Partially correct |
46 ms |
6132 KB |
Partially correct - number of queries: 8340 |
19 |
Correct |
3 ms |
4952 KB |
Output is correct |
20 |
Correct |
14 ms |
5208 KB |
Output is correct |
21 |
Correct |
23 ms |
5168 KB |
Output is correct |
22 |
Correct |
8 ms |
5208 KB |
Output is correct |
23 |
Correct |
6 ms |
5152 KB |
Output is correct |
24 |
Correct |
5 ms |
5164 KB |
Output is correct |
25 |
Correct |
34 ms |
5376 KB |
Output is correct |
26 |
Correct |
31 ms |
5300 KB |
Output is correct |
27 |
Correct |
6 ms |
5148 KB |
Output is correct |
28 |
Partially correct |
47 ms |
5576 KB |
Partially correct - number of queries: 7415 |
29 |
Partially correct |
39 ms |
5424 KB |
Partially correct - number of queries: 5937 |
30 |
Partially correct |
53 ms |
5624 KB |
Partially correct - number of queries: 8581 |
31 |
Correct |
4 ms |
4952 KB |
Output is correct |
32 |
Correct |
12 ms |
5160 KB |
Output is correct |
33 |
Correct |
2 ms |
4952 KB |
Output is correct |
34 |
Correct |
22 ms |
5348 KB |
Output is correct |
35 |
Correct |
7 ms |
5208 KB |
Output is correct |
36 |
Correct |
15 ms |
5464 KB |
Output is correct |
37 |
Correct |
8 ms |
5464 KB |
Output is correct |
38 |
Correct |
6 ms |
4952 KB |
Output is correct |
39 |
Correct |
24 ms |
5604 KB |
Output is correct |
40 |
Partially correct |
52 ms |
5636 KB |
Partially correct - number of queries: 7492 |
41 |
Partially correct |
28 ms |
5280 KB |
Partially correct - number of queries: 5421 |
42 |
Partially correct |
28 ms |
5500 KB |
Partially correct - number of queries: 5421 |
43 |
Partially correct |
33 ms |
5728 KB |
Partially correct - number of queries: 5057 |
44 |
Correct |
28 ms |
5456 KB |
Output is correct |
45 |
Correct |
15 ms |
5208 KB |
Output is correct |
46 |
Correct |
3 ms |
4952 KB |
Output is correct |
47 |
Correct |
32 ms |
5208 KB |
Output is correct |
48 |
Partially correct |
31 ms |
5472 KB |
Partially correct - number of queries: 6330 |
49 |
Correct |
9 ms |
5208 KB |
Output is correct |
50 |
Partially correct |
51 ms |
5812 KB |
Partially correct - number of queries: 8327 |
51 |
Correct |
16 ms |
5464 KB |
Output is correct |
52 |
Correct |
7 ms |
4952 KB |
Output is correct |
53 |
Correct |
8 ms |
5480 KB |
Output is correct |
54 |
Correct |
21 ms |
5392 KB |
Output is correct |
55 |
Correct |
4 ms |
4952 KB |
Output is correct |
56 |
Partially correct |
44 ms |
5492 KB |
Partially correct - number of queries: 8303 |
57 |
Partially correct |
31 ms |
5668 KB |
Partially correct - number of queries: 6537 |
58 |
Partially correct |
47 ms |
5728 KB |
Partially correct - number of queries: 6418 |
59 |
Partially correct |
22 ms |
5660 KB |
Partially correct - number of queries: 5418 |
60 |
Correct |
24 ms |
5208 KB |
Output is correct |
61 |
Correct |
7 ms |
5208 KB |
Output is correct |
62 |
Correct |
8 ms |
4952 KB |
Output is correct |
63 |
Correct |
7 ms |
5208 KB |
Output is correct |
64 |
Correct |
6 ms |
5208 KB |
Output is correct |
65 |
Correct |
5 ms |
4952 KB |
Output is correct |
66 |
Correct |
8 ms |
4952 KB |
Output is correct |
67 |
Correct |
6 ms |
5160 KB |
Output is correct |
68 |
Correct |
4 ms |
4952 KB |
Output is correct |
69 |
Correct |
8 ms |
5136 KB |
Output is correct |
70 |
Correct |
10 ms |
4952 KB |
Output is correct |
71 |
Partially correct |
61 ms |
5524 KB |
Partially correct - number of queries: 8692 |
72 |
Correct |
7 ms |
5208 KB |
Output is correct |
73 |
Partially correct |
39 ms |
5456 KB |
Partially correct - number of queries: 8579 |
74 |
Partially correct |
47 ms |
5860 KB |
Partially correct - number of queries: 8624 |
75 |
Correct |
7 ms |
5208 KB |
Output is correct |
76 |
Partially correct |
47 ms |
5636 KB |
Partially correct - number of queries: 7525 |
77 |
Partially correct |
45 ms |
5652 KB |
Partially correct - number of queries: 8175 |
78 |
Correct |
9 ms |
5208 KB |
Output is correct |
79 |
Correct |
21 ms |
5208 KB |
Output is correct |
80 |
Partially correct |
50 ms |
5492 KB |
Partially correct - number of queries: 8505 |
81 |
Partially correct |
44 ms |
5452 KB |
Partially correct - number of queries: 8227 |
82 |
Partially correct |
48 ms |
5352 KB |
Partially correct - number of queries: 8274 |
83 |
Correct |
7 ms |
5208 KB |
Output is correct |
84 |
Partially correct |
47 ms |
5456 KB |
Partially correct - number of queries: 6601 |
85 |
Partially correct |
46 ms |
5712 KB |
Partially correct - number of queries: 8358 |
86 |
Correct |
5 ms |
5208 KB |
Output is correct |
87 |
Correct |
6 ms |
5160 KB |
Output is correct |
88 |
Correct |
6 ms |
4952 KB |
Output is correct |
89 |
Correct |
5 ms |
4952 KB |
Output is correct |
90 |
Correct |
6 ms |
4952 KB |
Output is correct |
91 |
Correct |
8 ms |
4952 KB |
Output is correct |
92 |
Correct |
6 ms |
4952 KB |
Output is correct |
93 |
Correct |
6 ms |
5160 KB |
Output is correct |
94 |
Correct |
8 ms |
5424 KB |
Output is correct |
95 |
Correct |
9 ms |
5208 KB |
Output is correct |
96 |
Correct |
6 ms |
5208 KB |
Output is correct |
97 |
Correct |
6 ms |
4952 KB |
Output is correct |