#include "prize.h"
#include <bits/stdc++.h>
#define endl "\n"
#define yeap cout<<"YES"<<endl
#define nope cout<<"NO"<<endl
#define ll long long
using namespace std;
const ll max_gems = 480;
bool gems[200005];
std::vector<pair<ll,ll>> response;
vector<int> askk(int i) {
if(response[i] == make_pair(-1ll, -1ll)) {
vector<int> res = ask(i);
response[i] = make_pair(res[0], res[1]);
return res;
}
vector<int> res;
res.push_back(response[i].first);
res.push_back(response[i].second);
return res;
}
int find_best(int n) {
ll mx = 0;
response.resize(n+5, {-1,-1});
priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
// queue<int> lolipops;
{
vector<int> v = askk(0);
ll a = v[0];
ll b = v[1];
mx = a+b;
if(mx == 0) return 0;
// lolipops.push(0);
}
max_updated:
int cur_lolipop = 0, left, right;
while(!pq.empty()) pq.pop();
while(true) {
// cout << cur_lolipop << " " << 79 << endl;
vector<int> v = askk(cur_lolipop);
ll a = v[0];
ll b = v[1];
ll c = a+b;
if(c==0){
return cur_lolipop;
} else if(c == mx) {
pq.push({a, cur_lolipop});
} else if(mx < c) {
mx = c;
goto max_updated;
}
if(c != mx){
gems[cur_lolipop] = true;
cur_lolipop++;
} else {
left = a, right = b;
break;
}
}
while(right != 0) {
// cout << l << " " << r << endl;
int l = cur_lolipop+1, r = -1;
while(!pq.empty()) {
int x = pq.top().first;
if(x <= left) {
pq.pop();
continue;
}
r = pq.top().second;
break;
}
if(r == -1) r = n-1;
// cout << l << " " << r << endl;
while(l < r) {
int mid = (l+r)/2;
// cout << mid << " " << 105 << endl;
vector<int> v = askk(mid);
ll a = v[0];
ll b = v[1];
ll c = a+b;
// cout << c << endl;
if(c==0){
return mid;
} else if(c == mx) {
pq.push({a, mid});
} else if(mx < c) {
mx = c;
goto max_updated;
}
if(c < left + right) {
gems[mid] == true;
r = mid;
} else if(a == left) {
l = mid+1;
for(int i = l; i <= mid; i++) {
response[i] = {left, right};
}
} else {
r = mid - 1;
}
}
vector<int> v = askk(l);
ll a = v[0];
ll b = v[1];
ll c = a+b;
// cout << c << endl;
if(c==0){
return l;
} else if(c == mx) {
pq.push({a, l});
} else if(mx < c) {
mx = c;
goto max_updated;
}
gems[l] = true;
cur_lolipop = l+1;
// if(cur_lolipop==n){
// return cur_lolipop;
// }
while(true) {
// cout << cur_lolipop << " " << 134 << endl;
vector<int> v = askk(cur_lolipop);
ll a = v[0];
ll b = v[1];
ll c = a+b;
if(c==0){
return cur_lolipop;
} else if(c == mx) {
pq.push({a, cur_lolipop});
} else if(mx < c) {
mx = c;
goto max_updated;
}
if(c != mx){
gems[cur_lolipop] = true;
cur_lolipop++;
} else {
left = a, right = b;
break;
}
}
}
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:132:27: warning: statement has no effect [-Wunused-value]
132 | gems[mid] == true;
| ~~~~~~~~~~^~~~~~~
prize.cpp:39:73: warning: control reaches end of non-void function [-Wreturn-type]
39 | priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
1 ms |
3448 KB |
Output is correct |
3 |
Correct |
1 ms |
3416 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
2 ms |
3640 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
1 ms |
3508 KB |
Output is correct |
8 |
Correct |
2 ms |
3416 KB |
Output is correct |
9 |
Correct |
1 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3416 KB |
Output is correct |
2 |
Correct |
1 ms |
3416 KB |
Output is correct |
3 |
Correct |
2 ms |
3416 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
2 ms |
3416 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
1 ms |
3416 KB |
Output is correct |
8 |
Correct |
1 ms |
3416 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 ms |
3416 KB |
Output is correct |
11 |
Correct |
3 ms |
4108 KB |
Output is correct |
12 |
Correct |
2 ms |
3416 KB |
Output is correct |
13 |
Correct |
3 ms |
3884 KB |
Output is correct |
14 |
Correct |
1 ms |
784 KB |
Output is correct |
15 |
Correct |
5 ms |
3868 KB |
Output is correct |
16 |
Correct |
19 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
3416 KB |
Output is correct |
18 |
Correct |
21 ms |
4244 KB |
Output is correct |
19 |
Correct |
1 ms |
3416 KB |
Output is correct |
20 |
Correct |
6 ms |
2308 KB |
Output is correct |
21 |
Correct |
8 ms |
4128 KB |
Output is correct |
22 |
Correct |
2 ms |
3852 KB |
Output is correct |
23 |
Correct |
1 ms |
3416 KB |
Output is correct |
24 |
Correct |
1 ms |
3416 KB |
Output is correct |
25 |
Correct |
15 ms |
4192 KB |
Output is correct |
26 |
Correct |
12 ms |
3916 KB |
Output is correct |
27 |
Correct |
1 ms |
3604 KB |
Output is correct |
28 |
Correct |
20 ms |
4412 KB |
Output is correct |
29 |
Correct |
13 ms |
4728 KB |
Output is correct |
30 |
Correct |
23 ms |
4700 KB |
Output is correct |
31 |
Correct |
1 ms |
3416 KB |
Output is correct |
32 |
Correct |
4 ms |
4016 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
8 ms |
3888 KB |
Output is correct |
35 |
Correct |
2 ms |
3596 KB |
Output is correct |
36 |
Correct |
6 ms |
3636 KB |
Output is correct |
37 |
Correct |
2 ms |
3592 KB |
Output is correct |
38 |
Correct |
1 ms |
3416 KB |
Output is correct |
39 |
Correct |
15 ms |
4128 KB |
Output is correct |
40 |
Correct |
19 ms |
4448 KB |
Output is correct |
41 |
Correct |
17 ms |
4152 KB |
Output is correct |
42 |
Correct |
12 ms |
3916 KB |
Output is correct |
43 |
Correct |
15 ms |
4660 KB |
Output is correct |
44 |
Correct |
8 ms |
3876 KB |
Output is correct |
45 |
Correct |
6 ms |
4132 KB |
Output is correct |
46 |
Correct |
1 ms |
3416 KB |
Output is correct |
47 |
Correct |
10 ms |
4148 KB |
Output is correct |
48 |
Correct |
17 ms |
3956 KB |
Output is correct |
49 |
Correct |
3 ms |
3592 KB |
Output is correct |
50 |
Correct |
21 ms |
4424 KB |
Output is correct |
51 |
Correct |
11 ms |
4176 KB |
Output is correct |
52 |
Correct |
2 ms |
3416 KB |
Output is correct |
53 |
Correct |
2 ms |
3596 KB |
Output is correct |
54 |
Correct |
9 ms |
4396 KB |
Output is correct |
55 |
Correct |
2 ms |
3416 KB |
Output is correct |
56 |
Correct |
23 ms |
4732 KB |
Output is correct |
57 |
Correct |
15 ms |
4372 KB |
Output is correct |
58 |
Correct |
15 ms |
4420 KB |
Output is correct |
59 |
Correct |
14 ms |
4620 KB |
Output is correct |
60 |
Correct |
15 ms |
4416 KB |
Output is correct |
61 |
Correct |
2 ms |
3852 KB |
Output is correct |
62 |
Correct |
1 ms |
3672 KB |
Output is correct |
63 |
Correct |
2 ms |
3592 KB |
Output is correct |
64 |
Correct |
1 ms |
3596 KB |
Output is correct |
65 |
Correct |
1 ms |
3416 KB |
Output is correct |
66 |
Correct |
3 ms |
3416 KB |
Output is correct |
67 |
Correct |
2 ms |
3416 KB |
Output is correct |
68 |
Correct |
4 ms |
3416 KB |
Output is correct |
69 |
Correct |
3 ms |
3416 KB |
Output is correct |
70 |
Correct |
1 ms |
3416 KB |
Output is correct |
71 |
Correct |
21 ms |
4200 KB |
Output is correct |
72 |
Correct |
4 ms |
4404 KB |
Output is correct |
73 |
Correct |
22 ms |
4440 KB |
Output is correct |
74 |
Correct |
21 ms |
3992 KB |
Output is correct |
75 |
Correct |
2 ms |
3588 KB |
Output is correct |
76 |
Correct |
23 ms |
4452 KB |
Output is correct |
77 |
Correct |
26 ms |
4716 KB |
Output is correct |
78 |
Correct |
3 ms |
3848 KB |
Output is correct |
79 |
Correct |
13 ms |
4376 KB |
Output is correct |
80 |
Correct |
27 ms |
4356 KB |
Output is correct |
81 |
Correct |
23 ms |
4164 KB |
Output is correct |
82 |
Correct |
26 ms |
4744 KB |
Output is correct |
83 |
Correct |
2 ms |
3584 KB |
Output is correct |
84 |
Correct |
23 ms |
3904 KB |
Output is correct |
85 |
Correct |
28 ms |
4932 KB |
Output is correct |
86 |
Correct |
24 ms |
4352 KB |
Output is correct |
87 |
Correct |
3 ms |
4096 KB |
Output is correct |
88 |
Correct |
21 ms |
4384 KB |
Output is correct |
89 |
Correct |
23 ms |
4420 KB |
Output is correct |
90 |
Correct |
2 ms |
3844 KB |
Output is correct |
91 |
Correct |
13 ms |
4136 KB |
Output is correct |
92 |
Correct |
12 ms |
3896 KB |
Output is correct |
93 |
Correct |
3 ms |
3864 KB |
Output is correct |
94 |
Correct |
3 ms |
3864 KB |
Output is correct |
95 |
Correct |
3 ms |
4116 KB |
Output is correct |
96 |
Correct |
3 ms |
4132 KB |
Output is correct |
97 |
Correct |
2 ms |
3416 KB |
Output is correct |