#include "bits/stdc++.h"
#include "prize.h"
//#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){
return l + rng() % (r-l+1);
}
const int BL = 500;
int suf = -1;
vector<int> Cache={-1,-1};
map<int,vector<int>> dp;
vector<int> Ask(int i){
if( dp.count(i) ) return dp[i];
return dp[i] = ask(i);
}
int ask_all(int l,int r){
for(int i = l; i <= r; i++){
vector<int> x = Ask(i);
if(x[0] + x[1] == 0) return i;
if(x[1] == suf) Cache = x;
else suf--;
}
return -23;
}
int Learn(int l,int r){
if(l>r) return -1;
if(l==r){
auto u = Ask(l);
if(u[0] + u[1] == 0) return l;
if(u[1] == suf) Cache=u;
else suf--;
return -1;
}
auto X = Ask(r);
if(X[0] + X[1] == 0) return r;
if(X[1] == suf) return -1;
if(l+BL+1<r){
auto u = Ask(l + BL);
if(u[0]+u[1]==0) return l+BL;
if(u[1] == suf) return Learn(l+BL+1,r-1);
int hm = Learn(l,l+BL-1);
if(hm != -1) return hm;
if(u[1] == suf) Cache = u;
else suf--;
if(X[1] == suf - ( Cache[0] + Cache[1] > X[0] + X[1] ) ) return -1;
int hm2 = Learn(l+BL+1,r-1);
if(hm2 != -1) return hm2;
if(X[1] == suf) Cache = X;
else suf--;
return -1;
}
int mid = (l+r) / 2;
auto u = Ask(mid);
if(u[0] + u[1] == 0) return mid;
if(u[1] == suf) return Learn(mid + 1,r - 1);
int lf = Learn(l,mid - 1);
if(lf != -1) return lf;
if(u[1]==suf) Cache = u;
else suf--;
if(X[1] == suf - ( Cache[0] + Cache[1] > X[0] + X[1] ) ) return -1;
int hm = Learn( mid + 1, r - 1 );
if(hm != -1) return hm;
if(X[1] == suf) Cache = X;
else suf--;
return -1;
}
int find_best(int n){
if(n <= 1000) return ask_all(0, n - 1);
int art = 0;
for(int i = 0; i <= 500; i++){
if(art == 5) return Learn(i, n - 1);
vector<int> x = Ask(i);
if(x[0] + x[1] == 0) return i;
if(x[0] + x[1] > Cache[0] + Cache[1]) art++;
if(x[0] + x[1] >= Cache[0] + Cache[1]){
Cache = x;
suf = Cache[1];
}
else suf--;
}
return Learn(501, n - 1 );
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
336 KB |
Output is correct |
2 |
Correct |
20 ms |
468 KB |
Output is correct |
3 |
Correct |
19 ms |
468 KB |
Output is correct |
4 |
Correct |
9 ms |
592 KB |
Output is correct |
5 |
Correct |
15 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
15 ms |
336 KB |
Output is correct |
8 |
Correct |
13 ms |
604 KB |
Output is correct |
9 |
Correct |
15 ms |
592 KB |
Output is correct |
10 |
Correct |
25 ms |
1000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
592 KB |
Output is correct |
2 |
Correct |
15 ms |
848 KB |
Output is correct |
3 |
Correct |
15 ms |
472 KB |
Output is correct |
4 |
Correct |
8 ms |
336 KB |
Output is correct |
5 |
Correct |
15 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
14 ms |
720 KB |
Output is correct |
8 |
Correct |
16 ms |
336 KB |
Output is correct |
9 |
Correct |
16 ms |
592 KB |
Output is correct |
10 |
Correct |
22 ms |
620 KB |
Output is correct |
11 |
Correct |
17 ms |
592 KB |
Output is correct |
12 |
Correct |
9 ms |
336 KB |
Output is correct |
13 |
Correct |
28 ms |
528 KB |
Output is correct |
14 |
Correct |
9 ms |
592 KB |
Output is correct |
15 |
Correct |
26 ms |
548 KB |
Output is correct |
16 |
Partially correct |
127 ms |
1424 KB |
Partially correct - number of queries: 6731 |
17 |
Correct |
8 ms |
460 KB |
Output is correct |
18 |
Partially correct |
162 ms |
1484 KB |
Partially correct - number of queries: 8062 |
19 |
Correct |
9 ms |
476 KB |
Output is correct |
20 |
Correct |
29 ms |
924 KB |
Output is correct |
21 |
Correct |
61 ms |
1340 KB |
Output is correct |
22 |
Correct |
18 ms |
592 KB |
Output is correct |
23 |
Correct |
11 ms |
336 KB |
Output is correct |
24 |
Correct |
9 ms |
336 KB |
Output is correct |
25 |
Correct |
78 ms |
1024 KB |
Output is correct |
26 |
Correct |
83 ms |
872 KB |
Output is correct |
27 |
Correct |
14 ms |
336 KB |
Output is correct |
28 |
Partially correct |
144 ms |
1408 KB |
Partially correct - number of queries: 6933 |
29 |
Partially correct |
101 ms |
1600 KB |
Partially correct - number of queries: 5536 |
30 |
Partially correct |
156 ms |
1744 KB |
Partially correct - number of queries: 7957 |
31 |
Correct |
8 ms |
336 KB |
Output is correct |
32 |
Correct |
23 ms |
824 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
52 ms |
932 KB |
Output is correct |
35 |
Correct |
20 ms |
848 KB |
Output is correct |
36 |
Correct |
42 ms |
776 KB |
Output is correct |
37 |
Correct |
15 ms |
592 KB |
Output is correct |
38 |
Correct |
11 ms |
336 KB |
Output is correct |
39 |
Correct |
88 ms |
736 KB |
Output is correct |
40 |
Partially correct |
149 ms |
1392 KB |
Partially correct - number of queries: 7076 |
41 |
Correct |
76 ms |
1580 KB |
Output is correct |
42 |
Correct |
87 ms |
1252 KB |
Output is correct |
43 |
Correct |
66 ms |
1072 KB |
Output is correct |
44 |
Correct |
51 ms |
888 KB |
Output is correct |
45 |
Correct |
45 ms |
928 KB |
Output is correct |
46 |
Correct |
8 ms |
712 KB |
Output is correct |
47 |
Correct |
68 ms |
812 KB |
Output is correct |
48 |
Partially correct |
102 ms |
1616 KB |
Partially correct - number of queries: 5807 |
49 |
Correct |
15 ms |
336 KB |
Output is correct |
50 |
Partially correct |
158 ms |
1504 KB |
Partially correct - number of queries: 8110 |
51 |
Correct |
54 ms |
1692 KB |
Output is correct |
52 |
Correct |
10 ms |
336 KB |
Output is correct |
53 |
Correct |
22 ms |
848 KB |
Output is correct |
54 |
Correct |
61 ms |
848 KB |
Output is correct |
55 |
Correct |
8 ms |
500 KB |
Output is correct |
56 |
Partially correct |
149 ms |
1348 KB |
Partially correct - number of queries: 7969 |
57 |
Partially correct |
101 ms |
1324 KB |
Partially correct - number of queries: 5708 |
58 |
Partially correct |
115 ms |
1528 KB |
Partially correct - number of queries: 5813 |
59 |
Correct |
88 ms |
980 KB |
Output is correct |
60 |
Correct |
93 ms |
972 KB |
Output is correct |
61 |
Correct |
24 ms |
828 KB |
Output is correct |
62 |
Correct |
12 ms |
848 KB |
Output is correct |
63 |
Correct |
21 ms |
744 KB |
Output is correct |
64 |
Correct |
16 ms |
548 KB |
Output is correct |
65 |
Correct |
8 ms |
336 KB |
Output is correct |
66 |
Correct |
9 ms |
472 KB |
Output is correct |
67 |
Correct |
19 ms |
592 KB |
Output is correct |
68 |
Correct |
8 ms |
592 KB |
Output is correct |
69 |
Correct |
9 ms |
592 KB |
Output is correct |
70 |
Correct |
17 ms |
592 KB |
Output is correct |
71 |
Partially correct |
153 ms |
1800 KB |
Partially correct - number of queries: 8697 |
72 |
Correct |
30 ms |
1248 KB |
Output is correct |
73 |
Partially correct |
163 ms |
1892 KB |
Partially correct - number of queries: 8599 |
74 |
Partially correct |
156 ms |
2400 KB |
Partially correct - number of queries: 8641 |
75 |
Correct |
22 ms |
592 KB |
Output is correct |
76 |
Partially correct |
136 ms |
1932 KB |
Partially correct - number of queries: 7689 |
77 |
Partially correct |
170 ms |
1716 KB |
Partially correct - number of queries: 8035 |
78 |
Correct |
32 ms |
916 KB |
Output is correct |
79 |
Correct |
87 ms |
1096 KB |
Output is correct |
80 |
Partially correct |
180 ms |
1864 KB |
Partially correct - number of queries: 8078 |
81 |
Partially correct |
148 ms |
1680 KB |
Partially correct - number of queries: 7972 |
82 |
Partially correct |
147 ms |
1444 KB |
Partially correct - number of queries: 7879 |
83 |
Correct |
25 ms |
592 KB |
Output is correct |
84 |
Partially correct |
134 ms |
2128 KB |
Partially correct - number of queries: 6876 |
85 |
Partially correct |
135 ms |
1624 KB |
Partially correct - number of queries: 7918 |
86 |
Correct |
23 ms |
752 KB |
Output is correct |
87 |
Correct |
22 ms |
748 KB |
Output is correct |
88 |
Correct |
20 ms |
556 KB |
Output is correct |
89 |
Correct |
19 ms |
608 KB |
Output is correct |
90 |
Correct |
24 ms |
1104 KB |
Output is correct |
91 |
Correct |
21 ms |
808 KB |
Output is correct |
92 |
Correct |
25 ms |
588 KB |
Output is correct |
93 |
Correct |
25 ms |
768 KB |
Output is correct |
94 |
Correct |
26 ms |
564 KB |
Output is correct |
95 |
Correct |
26 ms |
840 KB |
Output is correct |
96 |
Correct |
23 ms |
728 KB |
Output is correct |
97 |
Correct |
21 ms |
972 KB |
Output is correct |