#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
mt19937 rng(time(nullptr));
const int N=2e5+99;
int n,sum,mxc,ans=-1,fen[N];
vector<int> res;
void add(int x){
for(x++;x<N;x+=(x&-x)){
fen[x]++;
}
}
int get(int x){
int res=0;
for(x++;x;x-=(x&-x)){
res+=fen[x];
}
return res;
}
void solve(vector<int> vec,int cnt){
//cout<<"Cnt "<<cnt<<endl;
//dbgv(vec);
if(cnt==0) return ;
int mid;
while(vec.size()){
mid=int(vec.size())>>1;
res=ask(vec[mid]);
if(res[0]+res[1]==0){
//cout<<"ans -> "<<vec[mid]<<endl;
ans=vec[mid];
add(vec[mid]);
}
if(res[0]+res[1]<mxc){
cnt--;
add(vec[mid]);
vec.erase(vec.begin()+mid);
}
else{
break;
}
}
if(vec.size()==0) return ;
vector<int> lc,rc;
int cntl,cntr,res0=res[0];
f(i,0,mid) lc.pb(vec[i]);
f(i,mid+1,vec.size()) rc.pb(vec[i]);
cntl=res0-get(vec[mid]-1);
cntr=cnt-cntl;
solve(lc,cntl);
solve(rc,cntr);
}
int find_best(int _n){
n=_n;
srand(time(NULL));
uniform_int_distribution<int> rnd(0,n-1);
f(i,0,155){
int id=(1ll*rand()*rand()+rand())%n;
res=ask(id);
maxm(mxc,res[0]+res[1]);
}
vector<int> vec(n);
iota(all(vec),0);
solve(vec,mxc);
//eror(ans);
return ans;
}
Compilation message
prize.cpp: In function 'void solve(std::vector<int>, int)':
prize.cpp:9:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define f(i,a,b) for(int i=a;i<b;i++)
......
69 | f(i,mid+1,vec.size()) rc.pb(vec[i]);
| ~~~~~~~~~~~~~~~~~~
prize.cpp:69:2: note: in expansion of macro 'f'
69 | f(i,mid+1,vec.size()) rc.pb(vec[i]);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4284 KB |
Output is correct |
2 |
Correct |
7 ms |
4292 KB |
Output is correct |
3 |
Correct |
5 ms |
4260 KB |
Output is correct |
4 |
Correct |
5 ms |
4260 KB |
Output is correct |
5 |
Correct |
3 ms |
3116 KB |
Output is correct |
6 |
Correct |
5 ms |
4292 KB |
Output is correct |
7 |
Correct |
4 ms |
3112 KB |
Output is correct |
8 |
Correct |
6 ms |
3144 KB |
Output is correct |
9 |
Correct |
5 ms |
4300 KB |
Output is correct |
10 |
Correct |
5 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4280 KB |
Output is correct |
2 |
Correct |
6 ms |
4388 KB |
Output is correct |
3 |
Correct |
8 ms |
4264 KB |
Output is correct |
4 |
Correct |
6 ms |
4256 KB |
Output is correct |
5 |
Correct |
4 ms |
3120 KB |
Output is correct |
6 |
Correct |
4 ms |
4332 KB |
Output is correct |
7 |
Correct |
4 ms |
3104 KB |
Output is correct |
8 |
Correct |
4 ms |
3148 KB |
Output is correct |
9 |
Correct |
4 ms |
4264 KB |
Output is correct |
10 |
Correct |
5 ms |
4248 KB |
Output is correct |
11 |
Correct |
12 ms |
4772 KB |
Output is correct |
12 |
Correct |
15 ms |
4764 KB |
Output is correct |
13 |
Correct |
13 ms |
4700 KB |
Output is correct |
14 |
Correct |
11 ms |
840 KB |
Output is correct |
15 |
Correct |
45 ms |
5168 KB |
Output is correct |
16 |
Correct |
59 ms |
5140 KB |
Output is correct |
17 |
Correct |
60 ms |
5080 KB |
Output is correct |
18 |
Correct |
66 ms |
5176 KB |
Output is correct |
19 |
Correct |
50 ms |
5084 KB |
Output is correct |
20 |
Correct |
30 ms |
2720 KB |
Output is correct |
21 |
Correct |
99 ms |
5184 KB |
Output is correct |
22 |
Correct |
53 ms |
5168 KB |
Output is correct |
23 |
Correct |
9 ms |
4528 KB |
Output is correct |
24 |
Correct |
13 ms |
4636 KB |
Output is correct |
25 |
Correct |
51 ms |
5052 KB |
Output is correct |
26 |
Correct |
57 ms |
5168 KB |
Output is correct |
27 |
Correct |
9 ms |
4520 KB |
Output is correct |
28 |
Correct |
49 ms |
5156 KB |
Output is correct |
29 |
Correct |
42 ms |
5072 KB |
Output is correct |
30 |
Correct |
59 ms |
5148 KB |
Output is correct |
31 |
Correct |
62 ms |
5132 KB |
Output is correct |
32 |
Correct |
14 ms |
4712 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
33 ms |
5180 KB |
Output is correct |
35 |
Correct |
12 ms |
4504 KB |
Output is correct |
36 |
Correct |
65 ms |
5096 KB |
Output is correct |
37 |
Correct |
15 ms |
4608 KB |
Output is correct |
38 |
Correct |
12 ms |
4492 KB |
Output is correct |
39 |
Correct |
62 ms |
5176 KB |
Output is correct |
40 |
Correct |
56 ms |
5072 KB |
Output is correct |
41 |
Correct |
64 ms |
5148 KB |
Output is correct |
42 |
Correct |
55 ms |
5096 KB |
Output is correct |
43 |
Correct |
64 ms |
5148 KB |
Output is correct |
44 |
Correct |
55 ms |
5288 KB |
Output is correct |
45 |
Correct |
54 ms |
5120 KB |
Output is correct |
46 |
Correct |
59 ms |
5104 KB |
Output is correct |
47 |
Correct |
57 ms |
5140 KB |
Output is correct |
48 |
Correct |
71 ms |
5164 KB |
Output is correct |
49 |
Correct |
43 ms |
5172 KB |
Output is correct |
50 |
Correct |
59 ms |
5076 KB |
Output is correct |
51 |
Correct |
57 ms |
5216 KB |
Output is correct |
52 |
Correct |
63 ms |
5132 KB |
Output is correct |
53 |
Correct |
13 ms |
4472 KB |
Output is correct |
54 |
Correct |
35 ms |
5180 KB |
Output is correct |
55 |
Correct |
64 ms |
5092 KB |
Output is correct |
56 |
Correct |
54 ms |
5176 KB |
Output is correct |
57 |
Correct |
57 ms |
5096 KB |
Output is correct |
58 |
Correct |
62 ms |
5140 KB |
Output is correct |
59 |
Correct |
66 ms |
5156 KB |
Output is correct |
60 |
Correct |
66 ms |
5156 KB |
Output is correct |
61 |
Correct |
11 ms |
4516 KB |
Output is correct |
62 |
Correct |
11 ms |
4508 KB |
Output is correct |
63 |
Correct |
9 ms |
4468 KB |
Output is correct |
64 |
Correct |
9 ms |
4384 KB |
Output is correct |
65 |
Correct |
7 ms |
4392 KB |
Output is correct |
66 |
Correct |
8 ms |
4252 KB |
Output is correct |
67 |
Correct |
9 ms |
4288 KB |
Output is correct |
68 |
Correct |
7 ms |
4304 KB |
Output is correct |
69 |
Correct |
10 ms |
4264 KB |
Output is correct |
70 |
Correct |
7 ms |
4252 KB |
Output is correct |
71 |
Correct |
55 ms |
5148 KB |
Output is correct |
72 |
Correct |
13 ms |
4676 KB |
Output is correct |
73 |
Correct |
52 ms |
5300 KB |
Output is correct |
74 |
Correct |
50 ms |
5148 KB |
Output is correct |
75 |
Correct |
9 ms |
4420 KB |
Output is correct |
76 |
Correct |
52 ms |
5172 KB |
Output is correct |
77 |
Correct |
57 ms |
5164 KB |
Output is correct |
78 |
Correct |
14 ms |
4676 KB |
Output is correct |
79 |
Correct |
32 ms |
5084 KB |
Output is correct |
80 |
Correct |
48 ms |
5180 KB |
Output is correct |
81 |
Correct |
50 ms |
5232 KB |
Output is correct |
82 |
Correct |
48 ms |
5172 KB |
Output is correct |
83 |
Correct |
10 ms |
4420 KB |
Output is correct |
84 |
Correct |
28 ms |
5148 KB |
Output is correct |
85 |
Correct |
54 ms |
5212 KB |
Output is correct |
86 |
Correct |
27 ms |
5052 KB |
Output is correct |
87 |
Correct |
16 ms |
4620 KB |
Output is correct |
88 |
Correct |
25 ms |
5096 KB |
Output is correct |
89 |
Correct |
31 ms |
5152 KB |
Output is correct |
90 |
Correct |
10 ms |
4420 KB |
Output is correct |
91 |
Correct |
29 ms |
5116 KB |
Output is correct |
92 |
Correct |
24 ms |
5132 KB |
Output is correct |
93 |
Correct |
13 ms |
4604 KB |
Output is correct |
94 |
Correct |
21 ms |
4588 KB |
Output is correct |
95 |
Correct |
15 ms |
4592 KB |
Output is correct |
96 |
Correct |
11 ms |
4632 KB |
Output is correct |
97 |
Correct |
5 ms |
4268 KB |
Output is correct |