#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair <int,int>
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define en '\n'
#define all(v) v.begin(),v.end()
const int N = 2e5 + 10;
int k,mx,kol;
vector <int> was[N];
bool u[N],gd[N];
vector <pii> q;
int t[N * 4],t1[N * 4];
void build(int v,int tl,int tr) {
if(tl == tr) {
t[v] = 1;
t1[v] = 0;
return;
}
int tm = (tl + tr) / 2;
build(v + v,tl,tm);
build(v + v + 1,tm + 1,tr);
t[v] = t[v + v] + t[v + v + 1];
}
int get(int v,int tl,int tr,int x) {
if(tl == tr)return tl;
int tm = (tl + tr) / 2;
if(t[v + v] >= x)return get(v + v,tl,tm,x);
else return get(v + v + 1,tm + 1,tr,x - t[v + v]);
}
void upd(int v,int tl,int tr,int pos) {
if(tl == tr) {
t[v] = 0;
t1[v] = 1;
return;
}
int tm = (tl + tr) / 2;
if(pos <= tm)upd(v + v,tl,tm,pos);
else upd(v + v + 1,tm + 1,tr,pos);
t[v] = t[v + v] + t[v + v + 1];
t1[v] = t1[v + v] + t1[v + v + 1];
}
int get1(int v,int tl,int tr,int l,int r) {
if(tl > r || tr < l)return 0;
if(tl >= l && tr <= r)return t1[v];
int tm = (tl + tr) / 2;
return get1(v + v,tl,tm,l,r) + get1(v + v + 1,tm + 1,tr,l,r);
}
/*
8
3 2 3 1 3 3 2 3
*/
vector <int> Ask(int x) {
if(u[x])return was[x];
u[x] = 1;
kol++;
assert(kol <= 10000);
was[x] = ask(x);
return was[x];
}
int find_best(int pp) {
k = pp;
int m = (k - 1) / 2;
int mx = 1;
build(1,0,k - 1);
int pos = 0;
while(1) {
int l = 0,r = k - 1 - pos;
while(l <= r) {
int mid = (l + r) / 2;
int zap = get(1,0,k - 1,mid + 1);
vector <int> res = Ask(zap);
int sum = res[0] + res[1];
if(sum == 0)return zap;
if(sum < mx) {
pos++;
upd(1,0,k - 1,zap);
gd[zap] = 1;
break;
}
if(sum > mx) {
bool ch = 0;
for(int i = 0;i < k;i++) {
if(!gd[i] && u[i] && i != zap) {
pos++;
upd(1,0,k - 1,i);
ch = 1;
gd[i] = 1;
}
}
mx = sum;
if(ch)break;
}
res[0] -= get1(1,0,k - 1,0,zap - 1);
if(res[0] != 0) {
r = mid - 1;
}else {
l = mid + 1;
}
}
}
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:66:6: warning: unused variable 'm' [-Wunused-variable]
66 | int m = (k - 1) / 2;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8584 KB |
Output is correct |
2 |
Correct |
5 ms |
8580 KB |
Output is correct |
3 |
Correct |
5 ms |
8592 KB |
Output is correct |
4 |
Correct |
6 ms |
8516 KB |
Output is correct |
5 |
Correct |
5 ms |
8528 KB |
Output is correct |
6 |
Correct |
5 ms |
8588 KB |
Output is correct |
7 |
Correct |
6 ms |
8588 KB |
Output is correct |
8 |
Correct |
5 ms |
8528 KB |
Output is correct |
9 |
Correct |
5 ms |
8588 KB |
Output is correct |
10 |
Correct |
5 ms |
8528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8592 KB |
Output is correct |
2 |
Correct |
5 ms |
8616 KB |
Output is correct |
3 |
Correct |
5 ms |
8588 KB |
Output is correct |
4 |
Correct |
5 ms |
8528 KB |
Output is correct |
5 |
Correct |
6 ms |
8688 KB |
Output is correct |
6 |
Correct |
5 ms |
8592 KB |
Output is correct |
7 |
Correct |
5 ms |
8608 KB |
Output is correct |
8 |
Correct |
5 ms |
8588 KB |
Output is correct |
9 |
Correct |
6 ms |
8584 KB |
Output is correct |
10 |
Correct |
6 ms |
8528 KB |
Output is correct |
11 |
Correct |
7 ms |
8836 KB |
Output is correct |
12 |
Correct |
7 ms |
8520 KB |
Output is correct |
13 |
Correct |
9 ms |
9268 KB |
Output is correct |
14 |
Correct |
6 ms |
5508 KB |
Output is correct |
15 |
Correct |
12 ms |
8712 KB |
Output is correct |
16 |
Correct |
33 ms |
9500 KB |
Output is correct |
17 |
Correct |
5 ms |
8528 KB |
Output is correct |
18 |
Partially correct |
40 ms |
9704 KB |
Partially correct - number of queries: 5509 |
19 |
Correct |
5 ms |
8576 KB |
Output is correct |
20 |
Correct |
18 ms |
6984 KB |
Output is correct |
21 |
Correct |
19 ms |
8896 KB |
Output is correct |
22 |
Correct |
9 ms |
8688 KB |
Output is correct |
23 |
Correct |
6 ms |
8588 KB |
Output is correct |
24 |
Correct |
5 ms |
8584 KB |
Output is correct |
25 |
Correct |
30 ms |
9160 KB |
Output is correct |
26 |
Correct |
35 ms |
9140 KB |
Output is correct |
27 |
Correct |
6 ms |
8648 KB |
Output is correct |
28 |
Partially correct |
36 ms |
9548 KB |
Partially correct - number of queries: 5013 |
29 |
Correct |
38 ms |
9384 KB |
Output is correct |
30 |
Partially correct |
44 ms |
9648 KB |
Partially correct - number of queries: 5436 |
31 |
Correct |
5 ms |
8588 KB |
Output is correct |
32 |
Correct |
8 ms |
9096 KB |
Output is correct |
33 |
Correct |
2 ms |
4944 KB |
Output is correct |
34 |
Correct |
24 ms |
8836 KB |
Output is correct |
35 |
Correct |
7 ms |
8844 KB |
Output is correct |
36 |
Correct |
18 ms |
8832 KB |
Output is correct |
37 |
Correct |
7 ms |
8704 KB |
Output is correct |
38 |
Correct |
5 ms |
8576 KB |
Output is correct |
39 |
Correct |
23 ms |
9092 KB |
Output is correct |
40 |
Correct |
36 ms |
9588 KB |
Output is correct |
41 |
Correct |
33 ms |
9380 KB |
Output is correct |
42 |
Correct |
31 ms |
9132 KB |
Output is correct |
43 |
Correct |
19 ms |
9176 KB |
Output is correct |
44 |
Correct |
26 ms |
9024 KB |
Output is correct |
45 |
Correct |
21 ms |
8836 KB |
Output is correct |
46 |
Correct |
5 ms |
8584 KB |
Output is correct |
47 |
Correct |
26 ms |
9060 KB |
Output is correct |
48 |
Correct |
45 ms |
9344 KB |
Output is correct |
49 |
Correct |
12 ms |
8616 KB |
Output is correct |
50 |
Partially correct |
51 ms |
9580 KB |
Partially correct - number of queries: 5521 |
51 |
Correct |
27 ms |
8952 KB |
Output is correct |
52 |
Correct |
6 ms |
8572 KB |
Output is correct |
53 |
Correct |
7 ms |
8740 KB |
Output is correct |
54 |
Correct |
25 ms |
8964 KB |
Output is correct |
55 |
Correct |
6 ms |
8532 KB |
Output is correct |
56 |
Partially correct |
44 ms |
9620 KB |
Partially correct - number of queries: 5521 |
57 |
Correct |
38 ms |
9288 KB |
Output is correct |
58 |
Correct |
30 ms |
9348 KB |
Output is correct |
59 |
Correct |
48 ms |
9232 KB |
Output is correct |
60 |
Correct |
32 ms |
9092 KB |
Output is correct |
61 |
Correct |
7 ms |
8844 KB |
Output is correct |
62 |
Correct |
6 ms |
8604 KB |
Output is correct |
63 |
Correct |
7 ms |
8840 KB |
Output is correct |
64 |
Correct |
6 ms |
8704 KB |
Output is correct |
65 |
Correct |
8 ms |
8588 KB |
Output is correct |
66 |
Correct |
25 ms |
8752 KB |
Output is correct |
67 |
Correct |
12 ms |
8592 KB |
Output is correct |
68 |
Correct |
10 ms |
8656 KB |
Output is correct |
69 |
Correct |
34 ms |
8660 KB |
Output is correct |
70 |
Correct |
13 ms |
8584 KB |
Output is correct |
71 |
Partially correct |
49 ms |
9612 KB |
Partially correct - number of queries: 6126 |
72 |
Correct |
10 ms |
9260 KB |
Output is correct |
73 |
Partially correct |
65 ms |
9736 KB |
Partially correct - number of queries: 6016 |
74 |
Partially correct |
52 ms |
9636 KB |
Partially correct - number of queries: 6033 |
75 |
Correct |
7 ms |
8784 KB |
Output is correct |
76 |
Partially correct |
35 ms |
9792 KB |
Partially correct - number of queries: 5202 |
77 |
Partially correct |
60 ms |
9580 KB |
Partially correct - number of queries: 5621 |
78 |
Correct |
9 ms |
9304 KB |
Output is correct |
79 |
Correct |
32 ms |
9452 KB |
Output is correct |
80 |
Partially correct |
56 ms |
9736 KB |
Partially correct - number of queries: 5602 |
81 |
Partially correct |
58 ms |
9544 KB |
Partially correct - number of queries: 5539 |
82 |
Partially correct |
58 ms |
9560 KB |
Partially correct - number of queries: 5524 |
83 |
Correct |
7 ms |
8868 KB |
Output is correct |
84 |
Correct |
42 ms |
9544 KB |
Output is correct |
85 |
Partially correct |
48 ms |
9656 KB |
Partially correct - number of queries: 5540 |
86 |
Correct |
11 ms |
9420 KB |
Output is correct |
87 |
Correct |
6 ms |
9000 KB |
Output is correct |
88 |
Correct |
17 ms |
9444 KB |
Output is correct |
89 |
Correct |
19 ms |
9416 KB |
Output is correct |
90 |
Correct |
6 ms |
8656 KB |
Output is correct |
91 |
Correct |
11 ms |
9316 KB |
Output is correct |
92 |
Correct |
11 ms |
8872 KB |
Output is correct |
93 |
Correct |
7 ms |
8940 KB |
Output is correct |
94 |
Correct |
11 ms |
9036 KB |
Output is correct |
95 |
Correct |
9 ms |
9040 KB |
Output is correct |
96 |
Correct |
8 ms |
9040 KB |
Output is correct |
97 |
Correct |
5 ms |
8528 KB |
Output is correct |