#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> cache[200005];
vector<int> myask(int x){
if(cache[x].empty())cache[x]=ask(x);
return cache[x];
}
int Maxm[200005];
int find_best(int n) {
int Maxnum=0;
for(int i = 0;i<n&&i<500;i++){
vector<int> v=myask(i);
if(v[0]+v[1]==0)return i;
Maxnum=max(Maxnum,v[0]+v[1]);
}
int l=0,r=n-1;
int num=0;
while(true){
int Max=r,Min=l;
// printf("%d %d\n",Max,Min);
while(Max>Min){
int mid=(Max+Min)/2;
vector<int> v=myask(mid);
if(v[0]+v[1]==0)return mid;
if(v[0]+v[1]!=Maxnum){
Max=mid;
}
else{
Maxm[v[0]]=max(Maxm[v[0]],mid);
if(v[0]-num)Max=mid-1;
else Min=mid+1;
}
}
num++;
Maxm[num]=max(Maxm[num],Max);
vector<int> v=myask(Max);
if(v[0]+v[1]==0)return Max;
// printf("? %d %d %d\n",v[0],v[1],num);
l=Maxm[num]+1;
}
/*
int Max=n-1,Min=0;
while(Max>Min){
int mid=(Max+Min)/2;
vector<int> v=ask(mid);
if(v[0]+v[1]==0){
return mid;
}
if(v[0]<v[1]){
Min=mid+1;
}
else{
Max=mid-1;
}
}
return Min;*/
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5128 KB |
Output is correct |
2 |
Correct |
9 ms |
4992 KB |
Output is correct |
3 |
Correct |
9 ms |
4992 KB |
Output is correct |
4 |
Correct |
9 ms |
5096 KB |
Output is correct |
5 |
Correct |
9 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
8 ms |
4992 KB |
Output is correct |
8 |
Correct |
6 ms |
5212 KB |
Output is correct |
9 |
Correct |
9 ms |
4992 KB |
Output is correct |
10 |
Correct |
11 ms |
4992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4992 KB |
Output is correct |
2 |
Correct |
6 ms |
5128 KB |
Output is correct |
3 |
Correct |
11 ms |
4992 KB |
Output is correct |
4 |
Correct |
9 ms |
5112 KB |
Output is correct |
5 |
Correct |
8 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
10 ms |
4992 KB |
Output is correct |
8 |
Correct |
9 ms |
4992 KB |
Output is correct |
9 |
Correct |
12 ms |
4992 KB |
Output is correct |
10 |
Correct |
9 ms |
4992 KB |
Output is correct |
11 |
Correct |
8 ms |
5144 KB |
Output is correct |
12 |
Correct |
10 ms |
4992 KB |
Output is correct |
13 |
Correct |
10 ms |
5092 KB |
Output is correct |
14 |
Correct |
12 ms |
4992 KB |
Output is correct |
15 |
Correct |
14 ms |
5160 KB |
Output is correct |
16 |
Partially correct |
59 ms |
5280 KB |
Partially correct - number of queries: 6600 |
17 |
Correct |
6 ms |
5128 KB |
Output is correct |
18 |
Partially correct |
89 ms |
5348 KB |
Partially correct - number of queries: 7657 |
19 |
Correct |
6 ms |
5128 KB |
Output is correct |
20 |
Correct |
27 ms |
5112 KB |
Output is correct |
21 |
Correct |
40 ms |
5112 KB |
Output is correct |
22 |
Correct |
15 ms |
4992 KB |
Output is correct |
23 |
Correct |
7 ms |
5188 KB |
Output is correct |
24 |
Correct |
10 ms |
4992 KB |
Output is correct |
25 |
Correct |
40 ms |
5176 KB |
Output is correct |
26 |
Correct |
54 ms |
5216 KB |
Output is correct |
27 |
Correct |
10 ms |
4992 KB |
Output is correct |
28 |
Partially correct |
64 ms |
5376 KB |
Partially correct - number of queries: 7413 |
29 |
Partially correct |
34 ms |
5296 KB |
Partially correct - number of queries: 5772 |
30 |
Partially correct |
75 ms |
5272 KB |
Partially correct - number of queries: 7596 |
31 |
Correct |
11 ms |
4992 KB |
Output is correct |
32 |
Correct |
13 ms |
5196 KB |
Output is correct |
33 |
Correct |
3 ms |
4992 KB |
Output is correct |
34 |
Correct |
25 ms |
5264 KB |
Output is correct |
35 |
Correct |
12 ms |
4992 KB |
Output is correct |
36 |
Correct |
32 ms |
5112 KB |
Output is correct |
37 |
Correct |
12 ms |
4992 KB |
Output is correct |
38 |
Correct |
10 ms |
4992 KB |
Output is correct |
39 |
Correct |
39 ms |
5112 KB |
Output is correct |
40 |
Partially correct |
79 ms |
5240 KB |
Partially correct - number of queries: 6568 |
41 |
Correct |
66 ms |
5240 KB |
Output is correct |
42 |
Correct |
60 ms |
5112 KB |
Output is correct |
43 |
Correct |
40 ms |
5112 KB |
Output is correct |
44 |
Correct |
42 ms |
5240 KB |
Output is correct |
45 |
Correct |
32 ms |
5112 KB |
Output is correct |
46 |
Correct |
7 ms |
4992 KB |
Output is correct |
47 |
Correct |
53 ms |
5112 KB |
Output is correct |
48 |
Partially correct |
52 ms |
5240 KB |
Partially correct - number of queries: 5813 |
49 |
Correct |
9 ms |
5140 KB |
Output is correct |
50 |
Partially correct |
68 ms |
5368 KB |
Partially correct - number of queries: 7652 |
51 |
Correct |
52 ms |
5248 KB |
Output is correct |
52 |
Correct |
10 ms |
5056 KB |
Output is correct |
53 |
Correct |
9 ms |
4992 KB |
Output is correct |
54 |
Correct |
32 ms |
5112 KB |
Output is correct |
55 |
Correct |
12 ms |
4968 KB |
Output is correct |
56 |
Partially correct |
70 ms |
5240 KB |
Partially correct - number of queries: 7679 |
57 |
Partially correct |
74 ms |
5240 KB |
Partially correct - number of queries: 5705 |
58 |
Partially correct |
68 ms |
5240 KB |
Partially correct - number of queries: 5814 |
59 |
Correct |
44 ms |
5112 KB |
Output is correct |
60 |
Correct |
56 ms |
5112 KB |
Output is correct |
61 |
Correct |
11 ms |
4992 KB |
Output is correct |
62 |
Correct |
9 ms |
4992 KB |
Output is correct |
63 |
Correct |
11 ms |
5152 KB |
Output is correct |
64 |
Correct |
10 ms |
4992 KB |
Output is correct |
65 |
Correct |
13 ms |
4992 KB |
Output is correct |
66 |
Correct |
14 ms |
4992 KB |
Output is correct |
67 |
Correct |
9 ms |
4992 KB |
Output is correct |
68 |
Correct |
7 ms |
4992 KB |
Output is correct |
69 |
Correct |
16 ms |
4992 KB |
Output is correct |
70 |
Correct |
9 ms |
5120 KB |
Output is correct |
71 |
Partially correct |
58 ms |
5440 KB |
Partially correct - number of queries: 7848 |
72 |
Correct |
14 ms |
4992 KB |
Output is correct |
73 |
Partially correct |
89 ms |
5240 KB |
Partially correct - number of queries: 7709 |
74 |
Partially correct |
71 ms |
5436 KB |
Partially correct - number of queries: 7795 |
75 |
Correct |
11 ms |
4992 KB |
Output is correct |
76 |
Partially correct |
90 ms |
5240 KB |
Partially correct - number of queries: 6830 |
77 |
Partially correct |
56 ms |
5268 KB |
Partially correct - number of queries: 7599 |
78 |
Correct |
17 ms |
4992 KB |
Output is correct |
79 |
Correct |
37 ms |
5112 KB |
Output is correct |
80 |
Partially correct |
73 ms |
5244 KB |
Partially correct - number of queries: 7603 |
81 |
Partially correct |
70 ms |
5240 KB |
Partially correct - number of queries: 7637 |
82 |
Partially correct |
43 ms |
5264 KB |
Partially correct - number of queries: 7491 |
83 |
Correct |
10 ms |
4992 KB |
Output is correct |
84 |
Partially correct |
71 ms |
5240 KB |
Partially correct - number of queries: 6330 |
85 |
Partially correct |
93 ms |
5348 KB |
Partially correct - number of queries: 7685 |
86 |
Correct |
47 ms |
5156 KB |
Output is correct |
87 |
Correct |
12 ms |
4992 KB |
Output is correct |
88 |
Correct |
33 ms |
5240 KB |
Output is correct |
89 |
Correct |
62 ms |
5120 KB |
Output is correct |
90 |
Correct |
11 ms |
4992 KB |
Output is correct |
91 |
Correct |
31 ms |
5240 KB |
Output is correct |
92 |
Correct |
40 ms |
5112 KB |
Output is correct |
93 |
Correct |
55 ms |
5240 KB |
Output is correct |
94 |
Correct |
49 ms |
5268 KB |
Output is correct |
95 |
Correct |
46 ms |
5112 KB |
Output is correct |
96 |
Correct |
54 ms |
5200 KB |
Output is correct |
97 |
Correct |
24 ms |
5184 KB |
Output is correct |