#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 69;
vector <int> a;
int f[N], mx;
int n;
map <int, vector<int>> mp;
vector <int> ask2(int x){
if (mp.find(x) != mp.end()) return mp[x];
return mp[x] = ask(x);
}
void upd(int x){
x++;
for (int i = x; i <= n; i += i & (-i)) f[i]++;
}
int query(int x){
x++;
int res = 0;
for (int i = x; i; i -= i & (-i)) res += f[i];
return res;
}
void report(int x){
upd(a[x]);
a.erase(a.begin() + x);
}
int find(){
int l = 0, r = a.size() - 1;
while (l != r){
// cout << l << " " << r << "\n";
int m = (l + r)/2;
auto g = ask2(a[m]);
int g1 = query(a[m]);
// cout << m << " " << g[0] << " " << g1 << "\n";
if (g[0] + g[1] < mx){
if (g[0] + g[1] == 0) return a[m];
report(m);
return -1;
}
if (g1 < g[0]) {
r = m - 1;
} else {
l = m + 1;
}
}
// cout << l << " " << r << "\n";
auto g = ask2(a[l]);
if (g[0] + g[1] == 0) return a[l];
report(l);
return -1;
}
int find_best(int m) {
n = m;
vector<vector<int>> ok;
for (int i = 0; i < min(n, 500); i++){
auto get = ask2(i);
ok.push_back(get);
mx = max(mx, get[0] + get[1]);
}
// if (mx != 1){
// cout << n << "\n";
// for (auto x : ok){
// for (auto y : x) cout << y << " ";
// cout << "\n";
// }
// return 0;
// }
for (int i = 0; i < n; i++) a.push_back(i);
while (true){
int get = find();
if (get > -1) return get;
}
assert(false);
return 0;
}
// int main(){
// // int t; cin >> t;
// // while (t--){
// // int n = 3 + rand() % 10;
// // int x = rand() % n;
// // a.clear();
// // mx = 0;
// // for (int i = 0; i <= n; i++) f[i] = 0, a1[i] = a2[i] = 0;
// // for (int i = 0; i < x; i++) a2[i] = 1;
// // for (int i = x + 1; i < n; i++) a1[i] = 1;
// // int get = find_best(n);
// // if (get != x){
// // cout << n << " " << x << "\n";
// // return 0;
// // }
// // }
// int n; cin >> n;
// for (int i = 0; i < n; i++) cin >> a1[i];
// for (int i = 0; i < n; i++) cin >> a2[i];
// cout << find_best(n);
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1452 KB |
Output is correct |
2 |
Correct |
4 ms |
1536 KB |
Output is correct |
3 |
Correct |
6 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1512 KB |
Output is correct |
5 |
Correct |
5 ms |
1448 KB |
Output is correct |
6 |
Correct |
3 ms |
1516 KB |
Output is correct |
7 |
Correct |
5 ms |
1448 KB |
Output is correct |
8 |
Correct |
7 ms |
1504 KB |
Output is correct |
9 |
Correct |
3 ms |
1544 KB |
Output is correct |
10 |
Correct |
7 ms |
1520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1508 KB |
Output is correct |
2 |
Correct |
5 ms |
1484 KB |
Output is correct |
3 |
Correct |
6 ms |
1444 KB |
Output is correct |
4 |
Correct |
7 ms |
1492 KB |
Output is correct |
5 |
Correct |
4 ms |
1504 KB |
Output is correct |
6 |
Correct |
6 ms |
1440 KB |
Output is correct |
7 |
Correct |
5 ms |
1444 KB |
Output is correct |
8 |
Correct |
4 ms |
1496 KB |
Output is correct |
9 |
Correct |
4 ms |
1452 KB |
Output is correct |
10 |
Correct |
5 ms |
1484 KB |
Output is correct |
11 |
Correct |
7 ms |
1480 KB |
Output is correct |
12 |
Correct |
5 ms |
1492 KB |
Output is correct |
13 |
Correct |
7 ms |
1584 KB |
Output is correct |
14 |
Correct |
8 ms |
628 KB |
Output is correct |
15 |
Correct |
11 ms |
1512 KB |
Output is correct |
16 |
Partially correct |
47 ms |
2272 KB |
Partially correct - number of queries: 5037 |
17 |
Correct |
3 ms |
1508 KB |
Output is correct |
18 |
Partially correct |
44 ms |
2456 KB |
Partially correct - number of queries: 6000 |
19 |
Correct |
5 ms |
1516 KB |
Output is correct |
20 |
Correct |
16 ms |
1076 KB |
Output is correct |
21 |
Correct |
29 ms |
1588 KB |
Output is correct |
22 |
Correct |
12 ms |
1520 KB |
Output is correct |
23 |
Correct |
8 ms |
1532 KB |
Output is correct |
24 |
Correct |
3 ms |
1484 KB |
Output is correct |
25 |
Correct |
27 ms |
1928 KB |
Output is correct |
26 |
Correct |
37 ms |
1868 KB |
Output is correct |
27 |
Correct |
4 ms |
1544 KB |
Output is correct |
28 |
Partially correct |
29 ms |
2440 KB |
Partially correct - number of queries: 5501 |
29 |
Correct |
44 ms |
2180 KB |
Output is correct |
30 |
Partially correct |
46 ms |
2464 KB |
Partially correct - number of queries: 5931 |
31 |
Correct |
3 ms |
1516 KB |
Output is correct |
32 |
Correct |
8 ms |
1556 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
16 ms |
1600 KB |
Output is correct |
35 |
Correct |
6 ms |
1472 KB |
Output is correct |
36 |
Correct |
15 ms |
1484 KB |
Output is correct |
37 |
Correct |
4 ms |
1524 KB |
Output is correct |
38 |
Correct |
6 ms |
1500 KB |
Output is correct |
39 |
Correct |
21 ms |
1692 KB |
Output is correct |
40 |
Partially correct |
37 ms |
2388 KB |
Partially correct - number of queries: 5158 |
41 |
Correct |
35 ms |
1968 KB |
Output is correct |
42 |
Correct |
30 ms |
1944 KB |
Output is correct |
43 |
Correct |
19 ms |
1880 KB |
Output is correct |
44 |
Correct |
15 ms |
1644 KB |
Output is correct |
45 |
Correct |
19 ms |
1596 KB |
Output is correct |
46 |
Correct |
3 ms |
1504 KB |
Output is correct |
47 |
Correct |
27 ms |
1692 KB |
Output is correct |
48 |
Correct |
50 ms |
2116 KB |
Output is correct |
49 |
Correct |
11 ms |
1452 KB |
Output is correct |
50 |
Partially correct |
30 ms |
2540 KB |
Partially correct - number of queries: 6012 |
51 |
Correct |
15 ms |
1756 KB |
Output is correct |
52 |
Correct |
7 ms |
1436 KB |
Output is correct |
53 |
Correct |
7 ms |
1528 KB |
Output is correct |
54 |
Correct |
17 ms |
1740 KB |
Output is correct |
55 |
Correct |
5 ms |
1484 KB |
Output is correct |
56 |
Partially correct |
38 ms |
2468 KB |
Partially correct - number of queries: 6012 |
57 |
Correct |
27 ms |
2172 KB |
Output is correct |
58 |
Correct |
35 ms |
2092 KB |
Output is correct |
59 |
Correct |
39 ms |
1860 KB |
Output is correct |
60 |
Correct |
29 ms |
1872 KB |
Output is correct |
61 |
Correct |
6 ms |
1456 KB |
Output is correct |
62 |
Correct |
6 ms |
1496 KB |
Output is correct |
63 |
Correct |
7 ms |
1476 KB |
Output is correct |
64 |
Correct |
4 ms |
1488 KB |
Output is correct |
65 |
Correct |
6 ms |
1484 KB |
Output is correct |
66 |
Correct |
39 ms |
1616 KB |
Output is correct |
67 |
Correct |
12 ms |
1492 KB |
Output is correct |
68 |
Correct |
8 ms |
1484 KB |
Output is correct |
69 |
Correct |
25 ms |
1572 KB |
Output is correct |
70 |
Correct |
7 ms |
1452 KB |
Output is correct |
71 |
Partially correct |
63 ms |
2568 KB |
Partially correct - number of queries: 6565 |
72 |
Correct |
11 ms |
1620 KB |
Output is correct |
73 |
Partially correct |
67 ms |
2548 KB |
Partially correct - number of queries: 6504 |
74 |
Partially correct |
53 ms |
2508 KB |
Partially correct - number of queries: 6546 |
75 |
Correct |
4 ms |
1484 KB |
Output is correct |
76 |
Partially correct |
55 ms |
2468 KB |
Partially correct - number of queries: 5715 |
77 |
Partially correct |
57 ms |
2456 KB |
Partially correct - number of queries: 6070 |
78 |
Correct |
9 ms |
1600 KB |
Output is correct |
79 |
Correct |
20 ms |
2128 KB |
Output is correct |
80 |
Partially correct |
53 ms |
2440 KB |
Partially correct - number of queries: 6045 |
81 |
Partially correct |
62 ms |
2464 KB |
Partially correct - number of queries: 6047 |
82 |
Partially correct |
40 ms |
2516 KB |
Partially correct - number of queries: 6013 |
83 |
Correct |
8 ms |
1520 KB |
Output is correct |
84 |
Partially correct |
52 ms |
2360 KB |
Partially correct - number of queries: 5067 |
85 |
Partially correct |
46 ms |
2532 KB |
Partially correct - number of queries: 6043 |
86 |
Correct |
38 ms |
1592 KB |
Output is correct |
87 |
Correct |
9 ms |
1472 KB |
Output is correct |
88 |
Correct |
46 ms |
1464 KB |
Output is correct |
89 |
Correct |
36 ms |
1584 KB |
Output is correct |
90 |
Correct |
7 ms |
1524 KB |
Output is correct |
91 |
Correct |
29 ms |
1492 KB |
Output is correct |
92 |
Correct |
43 ms |
1536 KB |
Output is correct |
93 |
Correct |
38 ms |
1736 KB |
Output is correct |
94 |
Correct |
50 ms |
1732 KB |
Output is correct |
95 |
Correct |
50 ms |
1768 KB |
Output is correct |
96 |
Correct |
32 ms |
1728 KB |
Output is correct |
97 |
Correct |
35 ms |
1568 KB |
Output is correct |