#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include "prize.h"
using namespace std;
const int MAX_N=2e5+4;
int asked[MAX_N][2];
bool used[MAX_N];
set<int>kinds;
set<int>idx[MAX_N];
pair<int,int>query(int pos)
{
if(used[pos])return {asked[pos][0],asked[pos][1]};
used[pos]=1;
auto ve=ask(pos);
asked[pos][0]=ve[0];
asked[pos][1]=ve[1];
kinds.insert(ve[0]+ve[1]);
idx[ve[0]+ve[1]].insert(pos);
return {ve[0],ve[1]};
}
bool useless(int l,int r)
{
for(int x:kinds)
{
auto it1=idx[x].lower_bound(l);
auto it2=idx[x].upper_bound(r);
if(it1!=idx[x].begin() && it2!=idx[x].end())
{
it1--;
int pos1=(*it1);
int pos2=(*it2);
if(query(pos2).first-query(pos1).first==0)return 1;
}
}
return 0;
}
int ans=-1;
void rec(int l,int r)
{
if(l>r)return;
if(ans!=-1)return;
int mid=(l+r)/2;
auto cur=query(mid);
if(cur.first+cur.second==0){ans=mid;return;}
if(!useless(l,mid-1))rec(l,mid-1);
if(!useless(mid+1,r))rec(mid+1,r);
}
int find_best(int n)
{
rec(0,n-1);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Output is correct |
2 |
Correct |
6 ms |
9816 KB |
Output is correct |
3 |
Correct |
4 ms |
9816 KB |
Output is correct |
4 |
Correct |
5 ms |
9816 KB |
Output is correct |
5 |
Correct |
5 ms |
9816 KB |
Output is correct |
6 |
Correct |
5 ms |
9816 KB |
Output is correct |
7 |
Correct |
4 ms |
9816 KB |
Output is correct |
8 |
Correct |
4 ms |
9816 KB |
Output is correct |
9 |
Correct |
4 ms |
9816 KB |
Output is correct |
10 |
Correct |
5 ms |
9816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9816 KB |
Output is correct |
3 |
Correct |
4 ms |
10072 KB |
Output is correct |
4 |
Correct |
5 ms |
9816 KB |
Output is correct |
5 |
Correct |
5 ms |
9832 KB |
Output is correct |
6 |
Correct |
4 ms |
9816 KB |
Output is correct |
7 |
Correct |
4 ms |
9816 KB |
Output is correct |
8 |
Correct |
7 ms |
9816 KB |
Output is correct |
9 |
Correct |
4 ms |
9816 KB |
Output is correct |
10 |
Correct |
4 ms |
9816 KB |
Output is correct |
11 |
Correct |
6 ms |
10140 KB |
Output is correct |
12 |
Correct |
4 ms |
9816 KB |
Output is correct |
13 |
Correct |
7 ms |
10584 KB |
Output is correct |
14 |
Correct |
6 ms |
9816 KB |
Output is correct |
15 |
Correct |
7 ms |
10072 KB |
Output is correct |
16 |
Correct |
26 ms |
11296 KB |
Output is correct |
17 |
Correct |
4 ms |
9816 KB |
Output is correct |
18 |
Correct |
43 ms |
11916 KB |
Output is correct |
19 |
Correct |
4 ms |
9816 KB |
Output is correct |
20 |
Correct |
14 ms |
10072 KB |
Output is correct |
21 |
Correct |
16 ms |
10328 KB |
Output is correct |
22 |
Correct |
6 ms |
9816 KB |
Output is correct |
23 |
Correct |
5 ms |
9816 KB |
Output is correct |
24 |
Correct |
4 ms |
9816 KB |
Output is correct |
25 |
Correct |
19 ms |
10776 KB |
Output is correct |
26 |
Correct |
15 ms |
10744 KB |
Output is correct |
27 |
Correct |
4 ms |
9952 KB |
Output is correct |
28 |
Correct |
27 ms |
11344 KB |
Output is correct |
29 |
Correct |
16 ms |
11344 KB |
Output is correct |
30 |
Correct |
24 ms |
11600 KB |
Output is correct |
31 |
Correct |
5 ms |
9816 KB |
Output is correct |
32 |
Correct |
6 ms |
10328 KB |
Output is correct |
33 |
Correct |
4 ms |
9816 KB |
Output is correct |
34 |
Correct |
17 ms |
10304 KB |
Output is correct |
35 |
Correct |
5 ms |
10072 KB |
Output is correct |
36 |
Correct |
7 ms |
10072 KB |
Output is correct |
37 |
Correct |
5 ms |
9816 KB |
Output is correct |
38 |
Correct |
4 ms |
9816 KB |
Output is correct |
39 |
Correct |
16 ms |
10460 KB |
Output is correct |
40 |
Correct |
37 ms |
11676 KB |
Output is correct |
41 |
Correct |
22 ms |
10768 KB |
Output is correct |
42 |
Correct |
15 ms |
10724 KB |
Output is correct |
43 |
Correct |
16 ms |
10852 KB |
Output is correct |
44 |
Correct |
11 ms |
10584 KB |
Output is correct |
45 |
Correct |
9 ms |
10328 KB |
Output is correct |
46 |
Correct |
5 ms |
9816 KB |
Output is correct |
47 |
Correct |
12 ms |
10832 KB |
Output is correct |
48 |
Correct |
20 ms |
11280 KB |
Output is correct |
49 |
Correct |
7 ms |
10072 KB |
Output is correct |
50 |
Correct |
38 ms |
11672 KB |
Output is correct |
51 |
Correct |
18 ms |
10420 KB |
Output is correct |
52 |
Correct |
5 ms |
9816 KB |
Output is correct |
53 |
Correct |
5 ms |
10328 KB |
Output is correct |
54 |
Correct |
15 ms |
10584 KB |
Output is correct |
55 |
Correct |
4 ms |
9816 KB |
Output is correct |
56 |
Correct |
42 ms |
11764 KB |
Output is correct |
57 |
Correct |
23 ms |
11088 KB |
Output is correct |
58 |
Correct |
21 ms |
11184 KB |
Output is correct |
59 |
Correct |
20 ms |
11052 KB |
Output is correct |
60 |
Correct |
14 ms |
10832 KB |
Output is correct |
61 |
Correct |
5 ms |
10072 KB |
Output is correct |
62 |
Correct |
4 ms |
10064 KB |
Output is correct |
63 |
Correct |
5 ms |
10024 KB |
Output is correct |
64 |
Correct |
4 ms |
9968 KB |
Output is correct |
65 |
Correct |
4 ms |
9816 KB |
Output is correct |
66 |
Correct |
5 ms |
9816 KB |
Output is correct |
67 |
Correct |
5 ms |
9816 KB |
Output is correct |
68 |
Correct |
4 ms |
9816 KB |
Output is correct |
69 |
Correct |
4 ms |
9816 KB |
Output is correct |
70 |
Correct |
5 ms |
9816 KB |
Output is correct |
71 |
Correct |
38 ms |
11604 KB |
Output is correct |
72 |
Correct |
8 ms |
10584 KB |
Output is correct |
73 |
Correct |
28 ms |
11600 KB |
Output is correct |
74 |
Correct |
29 ms |
11820 KB |
Output is correct |
75 |
Correct |
6 ms |
10072 KB |
Output is correct |
76 |
Correct |
27 ms |
11656 KB |
Output is correct |
77 |
Correct |
29 ms |
11856 KB |
Output is correct |
78 |
Correct |
8 ms |
10584 KB |
Output is correct |
79 |
Correct |
20 ms |
11496 KB |
Output is correct |
80 |
Correct |
40 ms |
11856 KB |
Output is correct |
81 |
Correct |
26 ms |
11600 KB |
Output is correct |
82 |
Correct |
41 ms |
11600 KB |
Output is correct |
83 |
Correct |
5 ms |
10072 KB |
Output is correct |
84 |
Correct |
29 ms |
11708 KB |
Output is correct |
85 |
Correct |
32 ms |
11984 KB |
Output is correct |
86 |
Correct |
12 ms |
10392 KB |
Output is correct |
87 |
Correct |
8 ms |
10072 KB |
Output is correct |
88 |
Correct |
8 ms |
10328 KB |
Output is correct |
89 |
Correct |
7 ms |
10328 KB |
Output is correct |
90 |
Correct |
5 ms |
10072 KB |
Output is correct |
91 |
Correct |
7 ms |
10068 KB |
Output is correct |
92 |
Correct |
4 ms |
9816 KB |
Output is correct |
93 |
Correct |
8 ms |
10328 KB |
Output is correct |
94 |
Correct |
6 ms |
10260 KB |
Output is correct |
95 |
Correct |
7 ms |
10328 KB |
Output is correct |
96 |
Correct |
6 ms |
10328 KB |
Output is correct |
97 |
Correct |
6 ms |
9816 KB |
Output is correct |