#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int ma,mma;
pair<int,int> ret[200005];
int lt(int i){
if(ret[i].first==-1){
vector<int>x=ask(i);
ret[i]=make_pair(x[0],x[1]);
}
return ret[i].first;
}
int rt(int i){
if(ret[i].second==-1){
vector<int>x=ask(i);
ret[i]=make_pair(x[0],x[1]);
}
return ret[i].second;
}
int ss(int i){
return lt(i)+rt(i);
}
int type(int i){
int x=ss(i);
if(x==0)return i;
else if(ma<x){
mma=x;
return -1;
}else if(ma==x)return -2;
else return -3;
}
void left(int l,int &i){
while(l<=i&&type(i)==-3)i--;
}
void right(int r,int &i){
while(i<=r&&type(i)==-3)i++;
}
int solve(int l,int r,int s,int t){
if(r<l)return -3;
if(l==r)return type(l);
int ml=(l+r)/2,mr=ml;
left(l,ml);
int res=-3;
if(l<=ml&&type(ml)>=-1)return type(ml);
if(l<ml&&s-rt(ml)>0)res=solve(l,ml-1,s,rt(ml));
if(res>=-1)return res;
right(r,mr);
if(mr<=r&&type(mr)>=-1)return type(mr);
if(mr<r&&rt(mr)-t>0)res=solve(mr+1,r,rt(mr),t);
return res;
}
int find_best(int n){
for(int i=0;i<n;i++)ret[i]=make_pair(-1,-1);
for(int i=0;i<100;i++){
if(type(i)>=0)return type(i);
ma=mma;
}
while(1){
ma=mma;
int la=100;
right(n-1,la);
if(type(la)>=0)return type(la);
if(type(la)==-1)continue;
while(1){
int pl=min(la+256,n-1),pr=pl;
left(la,pl);
if(type(pl)>=0)return type(pl);
if(type(pl)==-1)break;
int res=solve(la+1,pl-1,rt(la),rt(pl));
if(res>=0)return res;
if(res==-1)break;
right(n-1,pr);
if(type(pr)>=0)return type(pr);
if(type(pr)==-1)return -1;
la=pr;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1804 KB |
Output is correct |
2 |
Correct |
15 ms |
1828 KB |
Output is correct |
3 |
Correct |
6 ms |
1828 KB |
Output is correct |
4 |
Correct |
9 ms |
1832 KB |
Output is correct |
5 |
Correct |
10 ms |
1820 KB |
Output is correct |
6 |
Correct |
2 ms |
1736 KB |
Output is correct |
7 |
Correct |
11 ms |
1832 KB |
Output is correct |
8 |
Correct |
6 ms |
1856 KB |
Output is correct |
9 |
Correct |
10 ms |
1736 KB |
Output is correct |
10 |
Correct |
22 ms |
1736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1824 KB |
Output is correct |
2 |
Correct |
7 ms |
1824 KB |
Output is correct |
3 |
Correct |
13 ms |
1728 KB |
Output is correct |
4 |
Correct |
9 ms |
1856 KB |
Output is correct |
5 |
Correct |
10 ms |
1736 KB |
Output is correct |
6 |
Correct |
2 ms |
1736 KB |
Output is correct |
7 |
Correct |
10 ms |
1828 KB |
Output is correct |
8 |
Correct |
9 ms |
1736 KB |
Output is correct |
9 |
Correct |
13 ms |
1736 KB |
Output is correct |
10 |
Correct |
23 ms |
1736 KB |
Output is correct |
11 |
Correct |
6 ms |
1832 KB |
Output is correct |
12 |
Correct |
2 ms |
1856 KB |
Output is correct |
13 |
Correct |
23 ms |
1736 KB |
Output is correct |
14 |
Correct |
3 ms |
456 KB |
Output is correct |
15 |
Correct |
12 ms |
1736 KB |
Output is correct |
16 |
Correct |
20 ms |
1828 KB |
Output is correct |
17 |
Correct |
3 ms |
1736 KB |
Output is correct |
18 |
Correct |
46 ms |
1824 KB |
Output is correct |
19 |
Correct |
3 ms |
1832 KB |
Output is correct |
20 |
Correct |
7 ms |
1096 KB |
Output is correct |
21 |
Correct |
22 ms |
1736 KB |
Output is correct |
22 |
Correct |
8 ms |
1832 KB |
Output is correct |
23 |
Correct |
5 ms |
1832 KB |
Output is correct |
24 |
Correct |
3 ms |
1824 KB |
Output is correct |
25 |
Correct |
33 ms |
1728 KB |
Output is correct |
26 |
Correct |
28 ms |
1736 KB |
Output is correct |
27 |
Correct |
8 ms |
1828 KB |
Output is correct |
28 |
Correct |
64 ms |
1736 KB |
Output is correct |
29 |
Correct |
53 ms |
1828 KB |
Output is correct |
30 |
Correct |
32 ms |
1824 KB |
Output is correct |
31 |
Correct |
3 ms |
1736 KB |
Output is correct |
32 |
Correct |
12 ms |
1820 KB |
Output is correct |
33 |
Correct |
1 ms |
200 KB |
Output is correct |
34 |
Correct |
15 ms |
1828 KB |
Output is correct |
35 |
Correct |
16 ms |
1736 KB |
Output is correct |
36 |
Correct |
17 ms |
1736 KB |
Output is correct |
37 |
Correct |
7 ms |
1736 KB |
Output is correct |
38 |
Correct |
3 ms |
1828 KB |
Output is correct |
39 |
Correct |
12 ms |
1856 KB |
Output is correct |
40 |
Correct |
25 ms |
1812 KB |
Output is correct |
41 |
Correct |
39 ms |
1736 KB |
Output is correct |
42 |
Correct |
41 ms |
1824 KB |
Output is correct |
43 |
Correct |
34 ms |
1736 KB |
Output is correct |
44 |
Correct |
11 ms |
1848 KB |
Output is correct |
45 |
Correct |
17 ms |
1728 KB |
Output is correct |
46 |
Correct |
2 ms |
1820 KB |
Output is correct |
47 |
Correct |
28 ms |
1812 KB |
Output is correct |
48 |
Correct |
45 ms |
1736 KB |
Output is correct |
49 |
Correct |
4 ms |
1828 KB |
Output is correct |
50 |
Correct |
40 ms |
1728 KB |
Output is correct |
51 |
Correct |
25 ms |
1728 KB |
Output is correct |
52 |
Correct |
4 ms |
1824 KB |
Output is correct |
53 |
Correct |
10 ms |
1820 KB |
Output is correct |
54 |
Correct |
22 ms |
1736 KB |
Output is correct |
55 |
Correct |
3 ms |
1736 KB |
Output is correct |
56 |
Correct |
60 ms |
1736 KB |
Output is correct |
57 |
Correct |
46 ms |
1736 KB |
Output is correct |
58 |
Correct |
32 ms |
1824 KB |
Output is correct |
59 |
Correct |
38 ms |
1836 KB |
Output is correct |
60 |
Correct |
13 ms |
1828 KB |
Output is correct |
61 |
Correct |
15 ms |
1736 KB |
Output is correct |
62 |
Correct |
4 ms |
1836 KB |
Output is correct |
63 |
Correct |
18 ms |
1832 KB |
Output is correct |
64 |
Correct |
15 ms |
1736 KB |
Output is correct |
65 |
Correct |
9 ms |
1824 KB |
Output is correct |
66 |
Correct |
18 ms |
1860 KB |
Output is correct |
67 |
Correct |
24 ms |
1824 KB |
Output is correct |
68 |
Correct |
8 ms |
1828 KB |
Output is correct |
69 |
Correct |
26 ms |
1736 KB |
Output is correct |
70 |
Correct |
24 ms |
1736 KB |
Output is correct |
71 |
Correct |
35 ms |
1736 KB |
Output is correct |
72 |
Correct |
26 ms |
1736 KB |
Output is correct |
73 |
Correct |
56 ms |
1736 KB |
Output is correct |
74 |
Correct |
55 ms |
1736 KB |
Output is correct |
75 |
Correct |
13 ms |
1736 KB |
Output is correct |
76 |
Correct |
44 ms |
1736 KB |
Output is correct |
77 |
Correct |
47 ms |
1736 KB |
Output is correct |
78 |
Correct |
26 ms |
1736 KB |
Output is correct |
79 |
Correct |
35 ms |
1736 KB |
Output is correct |
80 |
Correct |
66 ms |
1736 KB |
Output is correct |
81 |
Correct |
57 ms |
1736 KB |
Output is correct |
82 |
Correct |
65 ms |
1736 KB |
Output is correct |
83 |
Correct |
17 ms |
1836 KB |
Output is correct |
84 |
Correct |
39 ms |
1828 KB |
Output is correct |
85 |
Correct |
47 ms |
1736 KB |
Output is correct |
86 |
Correct |
18 ms |
1736 KB |
Output is correct |
87 |
Correct |
22 ms |
1736 KB |
Output is correct |
88 |
Correct |
11 ms |
1864 KB |
Output is correct |
89 |
Correct |
19 ms |
1736 KB |
Output is correct |
90 |
Correct |
17 ms |
1736 KB |
Output is correct |
91 |
Correct |
25 ms |
1736 KB |
Output is correct |
92 |
Correct |
19 ms |
1736 KB |
Output is correct |
93 |
Correct |
44 ms |
1736 KB |
Output is correct |
94 |
Correct |
55 ms |
1736 KB |
Output is correct |
95 |
Correct |
40 ms |
1736 KB |
Output is correct |
96 |
Correct |
58 ms |
1736 KB |
Output is correct |
97 |
Correct |
20 ms |
1864 KB |
Output is correct |