#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define N ((int)201*1000)
int n,arr[N],lft[N],rght[N];
int cnt_rght[N],cnt_lft[N];
bool mark[N];
bool query(int x)
{
if(lft[x]+rght[x]>0)return 0;
vector <int> vec;vec=ask(x);
lft[x]=vec[0];rght[x]=vec[1];
return (lft[x]+rght[x]==0);
}
void add(int x)
{
mark[x]=1;
for(int i=x+1;i<n;i++)cnt_lft[i]++;
for(int i=x-1;i>=0;i--)cnt_rght[i]++;
return ;
}
int find_best(int n2)
{
n=n2;
int now=0,id;
queue <pair<int,int> > q;
q.push({-1,n});
for(int i=0;i<600 && q.size();i++)
{
int l=q.front().first,r=q.front().second;q.pop();
if(l>=r-1)continue;
int mid=(l+r)/2;
if(query(mid))return mid;
if(now<lft[mid]+rght[mid])
now=lft[mid]+rght[mid],id=mid;
q.push({l,mid});
q.push({mid,r});
}
while(q.size())q.pop();
q.push({-1,n});
for(int i=0;i<600 && q.size();i++)
{
int l=q.front().first,r=q.front().second;q.pop();
if(l>=r-1)continue;
int mid=(l+r)/2;
if(now>lft[mid]+rght[mid])
add(mid);
q.push({l,mid});
q.push({mid,r});
}
while(1)
{
int l=-1,r=n;
while(l<r-1)
{
int mid=(l+r)/2;
for(int i=0;;i++)
{
if(mid+i<r && !mark[mid+i])
{
mid=mid+i;
break;
}
if(mid-i>l && !mark[mid-i])
{
mid=mid-i;
break;
}
}
if(query(mid))return mid;
if(lft[mid]+rght[mid]<now)
{
add(mid);
break;
}
if((rght[mid]-cnt_rght[mid])-(rght[r]-cnt_rght[r])>0)l=mid;
else r=mid;
}
}
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:39:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(now<lft[mid]+rght[mid])
^~
prize.cpp:41:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
q.push({l,mid});
^
prize.cpp:51:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(now>lft[mid]+rght[mid])
^~
prize.cpp:53:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
q.push({l,mid});
^
prize.cpp:30:16: warning: variable 'id' set but not used [-Wunused-but-set-variable]
int now=0,id;
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1784 KB |
Output is correct |
2 |
Correct |
13 ms |
2012 KB |
Output is correct |
3 |
Correct |
10 ms |
2012 KB |
Output is correct |
4 |
Correct |
20 ms |
2012 KB |
Output is correct |
5 |
Correct |
15 ms |
2012 KB |
Output is correct |
6 |
Correct |
13 ms |
2040 KB |
Output is correct |
7 |
Correct |
13 ms |
2160 KB |
Output is correct |
8 |
Correct |
10 ms |
2160 KB |
Output is correct |
9 |
Correct |
2 ms |
2160 KB |
Output is correct |
10 |
Correct |
12 ms |
2160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2160 KB |
Output is correct |
2 |
Correct |
15 ms |
2160 KB |
Output is correct |
3 |
Correct |
15 ms |
2160 KB |
Output is correct |
4 |
Correct |
10 ms |
2160 KB |
Output is correct |
5 |
Correct |
17 ms |
2160 KB |
Output is correct |
6 |
Correct |
11 ms |
2160 KB |
Output is correct |
7 |
Correct |
13 ms |
2160 KB |
Output is correct |
8 |
Correct |
13 ms |
2160 KB |
Output is correct |
9 |
Correct |
3 ms |
2160 KB |
Output is correct |
10 |
Correct |
10 ms |
2160 KB |
Output is correct |
11 |
Correct |
21 ms |
3388 KB |
Output is correct |
12 |
Correct |
19 ms |
3772 KB |
Output is correct |
13 |
Correct |
7 ms |
3772 KB |
Output is correct |
14 |
Correct |
13 ms |
3772 KB |
Output is correct |
15 |
Correct |
93 ms |
3892 KB |
Output is correct |
16 |
Correct |
28 ms |
3892 KB |
Output is correct |
17 |
Correct |
107 ms |
3892 KB |
Output is correct |
18 |
Correct |
12 ms |
3892 KB |
Output is correct |
19 |
Correct |
108 ms |
3892 KB |
Output is correct |
20 |
Correct |
47 ms |
3892 KB |
Output is correct |
21 |
Correct |
71 ms |
3892 KB |
Output is correct |
22 |
Correct |
115 ms |
3916 KB |
Output is correct |
23 |
Correct |
17 ms |
3916 KB |
Output is correct |
24 |
Correct |
19 ms |
3916 KB |
Output is correct |
25 |
Correct |
48 ms |
3916 KB |
Output is correct |
26 |
Correct |
84 ms |
3916 KB |
Output is correct |
27 |
Correct |
9 ms |
3916 KB |
Output is correct |
28 |
Correct |
18 ms |
3916 KB |
Output is correct |
29 |
Correct |
23 ms |
3916 KB |
Output is correct |
30 |
Correct |
14 ms |
3916 KB |
Output is correct |
31 |
Correct |
154 ms |
3944 KB |
Output is correct |
32 |
Correct |
19 ms |
3944 KB |
Output is correct |
33 |
Correct |
2 ms |
3944 KB |
Output is correct |
34 |
Correct |
71 ms |
3944 KB |
Output is correct |
35 |
Correct |
17 ms |
3944 KB |
Output is correct |
36 |
Correct |
112 ms |
3944 KB |
Output is correct |
37 |
Correct |
30 ms |
3944 KB |
Output is correct |
38 |
Correct |
16 ms |
3944 KB |
Output is correct |
39 |
Correct |
96 ms |
3944 KB |
Output is correct |
40 |
Correct |
12 ms |
3944 KB |
Output is correct |
41 |
Correct |
72 ms |
3944 KB |
Output is correct |
42 |
Correct |
62 ms |
3944 KB |
Output is correct |
43 |
Correct |
80 ms |
3944 KB |
Output is correct |
44 |
Correct |
91 ms |
3944 KB |
Output is correct |
45 |
Correct |
76 ms |
3944 KB |
Output is correct |
46 |
Correct |
143 ms |
3944 KB |
Output is correct |
47 |
Correct |
71 ms |
3944 KB |
Output is correct |
48 |
Correct |
37 ms |
3944 KB |
Output is correct |
49 |
Correct |
130 ms |
3944 KB |
Output is correct |
50 |
Correct |
11 ms |
3944 KB |
Output is correct |
51 |
Correct |
104 ms |
3944 KB |
Output is correct |
52 |
Correct |
83 ms |
3944 KB |
Output is correct |
53 |
Correct |
16 ms |
3944 KB |
Output is correct |
54 |
Correct |
83 ms |
3944 KB |
Output is correct |
55 |
Correct |
144 ms |
3944 KB |
Output is correct |
56 |
Correct |
13 ms |
3944 KB |
Output is correct |
57 |
Correct |
49 ms |
3944 KB |
Output is correct |
58 |
Correct |
58 ms |
3944 KB |
Output is correct |
59 |
Correct |
73 ms |
3944 KB |
Output is correct |
60 |
Correct |
70 ms |
3944 KB |
Output is correct |
61 |
Correct |
19 ms |
3944 KB |
Output is correct |
62 |
Correct |
19 ms |
3944 KB |
Output is correct |
63 |
Correct |
23 ms |
3944 KB |
Output is correct |
64 |
Correct |
19 ms |
3944 KB |
Output is correct |
65 |
Correct |
16 ms |
3944 KB |
Output is correct |
66 |
Correct |
125 ms |
3944 KB |
Output is correct |
67 |
Correct |
49 ms |
3944 KB |
Output is correct |
68 |
Correct |
50 ms |
3944 KB |
Output is correct |
69 |
Correct |
85 ms |
3944 KB |
Output is correct |
70 |
Correct |
39 ms |
3944 KB |
Output is correct |
71 |
Correct |
168 ms |
3944 KB |
Output is correct |
72 |
Correct |
15 ms |
3944 KB |
Output is correct |
73 |
Correct |
141 ms |
3944 KB |
Output is correct |
74 |
Correct |
173 ms |
3944 KB |
Output is correct |
75 |
Correct |
16 ms |
3944 KB |
Output is correct |
76 |
Correct |
119 ms |
3944 KB |
Output is correct |
77 |
Correct |
151 ms |
3944 KB |
Output is correct |
78 |
Correct |
33 ms |
3944 KB |
Output is correct |
79 |
Correct |
55 ms |
3944 KB |
Output is correct |
80 |
Correct |
168 ms |
3944 KB |
Output is correct |
81 |
Correct |
176 ms |
3944 KB |
Output is correct |
82 |
Correct |
125 ms |
3944 KB |
Output is correct |
83 |
Correct |
14 ms |
3944 KB |
Output is correct |
84 |
Correct |
82 ms |
3944 KB |
Output is correct |
85 |
Correct |
121 ms |
3944 KB |
Output is correct |
86 |
Correct |
82 ms |
3944 KB |
Output is correct |
87 |
Correct |
25 ms |
3944 KB |
Output is correct |
88 |
Correct |
88 ms |
3944 KB |
Output is correct |
89 |
Correct |
91 ms |
3944 KB |
Output is correct |
90 |
Correct |
20 ms |
3944 KB |
Output is correct |
91 |
Correct |
47 ms |
3944 KB |
Output is correct |
92 |
Correct |
71 ms |
3944 KB |
Output is correct |
93 |
Correct |
79 ms |
3944 KB |
Output is correct |
94 |
Correct |
99 ms |
3944 KB |
Output is correct |
95 |
Correct |
87 ms |
3944 KB |
Output is correct |
96 |
Correct |
94 ms |
3944 KB |
Output is correct |
97 |
Correct |
77 ms |
3944 KB |
Output is correct |