#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
struct fenwick
{
int n;
vector < int > T;
fenwick(int n_)
{
n = n_ + 1;
T.resize(n);
}
void add(int i, int v)
{
for (int k = i+1; k < n; k+=k&-k) T[k] += v;
}
int query(int i)
{
int ans = 0;
for (int k = i+1; k; k -= k&-k) ans += T[k];
return ans;
}
};
int find_best(int n) {
map < int , map < int , int > > queried;
queue < pair < int , int > > toq;
toq.emplace(0, n);
fenwick ignore(n);
while(!toq.empty())
{
auto [l, r] = toq.front();
toq.pop();
int m = (l+r)/2;
cerr << m << " " << ignore.query(m) << "\n";
if (l >= r) continue;
if (ignore.query(m) > 0) continue;
cerr << "OK\n";
auto res = ask(m);
int left = res[0], right = res[1];
int key = left+right;
if (key == 0)
return m;
auto &occ = queried[key];
{
auto it = occ.upper_bound(m);
if (it != occ.end() && it->second == left)
{
while(it != occ.end() && it->second == left) it++;
it--;
int x = m, y = it->first;
ignore.add(y, -1);
ignore.add(x, 1);
cerr << "ehi" << x << " " << y << "\n";
}
}
{
auto it = occ.upper_bound(m);
if (it != occ.begin())
{
it--;
while(it->second == left && it != occ.begin()) it--;
it++;
if (it->second == left && it->first < m)
{
int x=it->first, y = m;
ignore.add(y, -1);
ignore.add(x, 1);
cerr << "ehi" << x << " " << y << "\n";
}
}
}
toq.emplace(l, m);
toq.emplace(m, r);
occ[m] = left;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1048 KB |
Output is correct |
2 |
Correct |
2 ms |
1052 KB |
Output is correct |
3 |
Correct |
2 ms |
1064 KB |
Output is correct |
4 |
Correct |
2 ms |
1060 KB |
Output is correct |
5 |
Correct |
1 ms |
1052 KB |
Output is correct |
6 |
Correct |
2 ms |
1096 KB |
Output is correct |
7 |
Correct |
1 ms |
1056 KB |
Output is correct |
8 |
Correct |
1 ms |
1056 KB |
Output is correct |
9 |
Correct |
2 ms |
1092 KB |
Output is correct |
10 |
Correct |
3 ms |
1104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
976 KB |
Output is correct |
2 |
Correct |
2 ms |
1052 KB |
Output is correct |
3 |
Correct |
3 ms |
968 KB |
Output is correct |
4 |
Correct |
2 ms |
1092 KB |
Output is correct |
5 |
Correct |
1 ms |
1060 KB |
Output is correct |
6 |
Correct |
2 ms |
1040 KB |
Output is correct |
7 |
Correct |
1 ms |
1060 KB |
Output is correct |
8 |
Correct |
1 ms |
1060 KB |
Output is correct |
9 |
Correct |
2 ms |
976 KB |
Output is correct |
10 |
Correct |
3 ms |
1104 KB |
Output is correct |
11 |
Correct |
12 ms |
1060 KB |
Output is correct |
12 |
Correct |
10 ms |
1104 KB |
Output is correct |
13 |
Correct |
16 ms |
1052 KB |
Output is correct |
14 |
Correct |
17 ms |
396 KB |
Output is correct |
15 |
Correct |
52 ms |
1164 KB |
Output is correct |
16 |
Correct |
86 ms |
1312 KB |
Output is correct |
17 |
Correct |
93 ms |
1300 KB |
Output is correct |
18 |
Correct |
94 ms |
1316 KB |
Output is correct |
19 |
Correct |
55 ms |
1248 KB |
Output is correct |
20 |
Correct |
48 ms |
836 KB |
Output is correct |
21 |
Correct |
93 ms |
1388 KB |
Output is correct |
22 |
Correct |
47 ms |
1196 KB |
Output is correct |
23 |
Correct |
4 ms |
968 KB |
Output is correct |
24 |
Correct |
10 ms |
1112 KB |
Output is correct |
25 |
Correct |
67 ms |
1168 KB |
Output is correct |
26 |
Correct |
76 ms |
1272 KB |
Output is correct |
27 |
Correct |
5 ms |
1048 KB |
Output is correct |
28 |
Correct |
70 ms |
1180 KB |
Output is correct |
29 |
Correct |
76 ms |
1272 KB |
Output is correct |
30 |
Correct |
77 ms |
1236 KB |
Output is correct |
31 |
Correct |
74 ms |
1244 KB |
Output is correct |
32 |
Correct |
9 ms |
1048 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Correct |
92 ms |
1304 KB |
Output is correct |
35 |
Correct |
8 ms |
1104 KB |
Output is correct |
36 |
Correct |
86 ms |
1228 KB |
Output is correct |
37 |
Correct |
10 ms |
1052 KB |
Output is correct |
38 |
Correct |
5 ms |
1060 KB |
Output is correct |
39 |
Correct |
87 ms |
1244 KB |
Output is correct |
40 |
Correct |
85 ms |
1516 KB |
Output is correct |
41 |
Correct |
98 ms |
1224 KB |
Output is correct |
42 |
Correct |
72 ms |
1504 KB |
Output is correct |
43 |
Correct |
93 ms |
1344 KB |
Output is correct |
44 |
Correct |
54 ms |
1212 KB |
Output is correct |
45 |
Correct |
62 ms |
1176 KB |
Output is correct |
46 |
Correct |
86 ms |
1512 KB |
Output is correct |
47 |
Correct |
69 ms |
1292 KB |
Output is correct |
48 |
Correct |
55 ms |
1248 KB |
Output is correct |
49 |
Correct |
81 ms |
1312 KB |
Output is correct |
50 |
Correct |
102 ms |
1300 KB |
Output is correct |
51 |
Correct |
80 ms |
1308 KB |
Output is correct |
52 |
Correct |
80 ms |
1296 KB |
Output is correct |
53 |
Correct |
5 ms |
1104 KB |
Output is correct |
54 |
Correct |
79 ms |
1504 KB |
Output is correct |
55 |
Correct |
79 ms |
1308 KB |
Output is correct |
56 |
Correct |
87 ms |
1276 KB |
Output is correct |
57 |
Correct |
49 ms |
1264 KB |
Output is correct |
58 |
Correct |
78 ms |
1340 KB |
Output is correct |
59 |
Correct |
99 ms |
1296 KB |
Output is correct |
60 |
Correct |
78 ms |
1200 KB |
Output is correct |
61 |
Correct |
4 ms |
1052 KB |
Output is correct |
62 |
Correct |
4 ms |
1036 KB |
Output is correct |
63 |
Correct |
5 ms |
1048 KB |
Output is correct |
64 |
Correct |
6 ms |
1096 KB |
Output is correct |
65 |
Correct |
2 ms |
1052 KB |
Output is correct |
66 |
Correct |
1 ms |
1056 KB |
Output is correct |
67 |
Correct |
2 ms |
1112 KB |
Output is correct |
68 |
Correct |
2 ms |
1064 KB |
Output is correct |
69 |
Correct |
3 ms |
1048 KB |
Output is correct |
70 |
Correct |
1 ms |
1080 KB |
Output is correct |
71 |
Correct |
127 ms |
1456 KB |
Output is correct |
72 |
Correct |
14 ms |
1224 KB |
Output is correct |
73 |
Correct |
136 ms |
1428 KB |
Output is correct |
74 |
Correct |
127 ms |
1440 KB |
Output is correct |
75 |
Correct |
6 ms |
1104 KB |
Output is correct |
76 |
Correct |
115 ms |
1360 KB |
Output is correct |
77 |
Correct |
97 ms |
1336 KB |
Output is correct |
78 |
Correct |
15 ms |
1096 KB |
Output is correct |
79 |
Correct |
68 ms |
1232 KB |
Output is correct |
80 |
Correct |
99 ms |
1300 KB |
Output is correct |
81 |
Correct |
91 ms |
1272 KB |
Output is correct |
82 |
Correct |
93 ms |
1232 KB |
Output is correct |
83 |
Correct |
4 ms |
1104 KB |
Output is correct |
84 |
Correct |
112 ms |
1224 KB |
Output is correct |
85 |
Correct |
107 ms |
1408 KB |
Output is correct |
86 |
Correct |
7 ms |
1108 KB |
Output is correct |
87 |
Correct |
4 ms |
1060 KB |
Output is correct |
88 |
Correct |
5 ms |
1104 KB |
Output is correct |
89 |
Correct |
5 ms |
1104 KB |
Output is correct |
90 |
Correct |
3 ms |
976 KB |
Output is correct |
91 |
Correct |
4 ms |
1060 KB |
Output is correct |
92 |
Correct |
3 ms |
1056 KB |
Output is correct |
93 |
Correct |
13 ms |
1104 KB |
Output is correct |
94 |
Correct |
11 ms |
1124 KB |
Output is correct |
95 |
Correct |
14 ms |
1108 KB |
Output is correct |
96 |
Correct |
7 ms |
1104 KB |
Output is correct |
97 |
Correct |
2 ms |
976 KB |
Output is correct |