#include <bits/stdc++.h>
#include "library.h"
using namespace std;
vector<vector<int> > blocks;
int N;
int query(vector<int> t){
vector<int> p(N);
for (int i = 0; i < N; i++)
p[i] = 0;
for (auto it : t)
p[it - 1] = 1;
return Query(p);
}
int ask(int lo, int hi, int v){
vector<int> t;
for (int i = lo; i < hi; i++)
for (auto it : blocks[i])
t.push_back(it);
t.push_back(v);
return query(t);
}
void Solve(int n){
N = n;
int cnt = 0;
for (int i = 1; i <= n; i++){
cnt = blocks.size();
if (ask(0, cnt, i) == cnt + 1)
blocks.push_back({i});
else{
int lo = 0, hi = cnt;
while (hi - lo > 1){
int mid = (lo + hi) >> 1;
if (ask(lo, mid, i) == (mid - lo + 1))
lo = mid;
else
hi = mid;
}
int fi = lo;
lo = 0, hi = cnt;
while (hi - lo > 1){
int mid = (lo + hi) >> 1;
if (ask(mid, hi, i) == (hi - mid + 1))
hi = mid;
else
lo = mid;
}
int se = lo;
if (fi != se){
if (blocks[fi].size() > 1 and query({blocks[fi][0], i}) == 1)
reverse(blocks[fi].begin(), blocks[fi].end());
if (blocks[se].size() > 1 and query({blocks[se].back(), i}) == 1)
reverse(blocks[se].begin(), blocks[se].end());
vector<int> q;
for (auto it : blocks[fi])
q.push_back(it);
q.push_back(i);
for (auto it : blocks[se])
q.push_back(it);
blocks.erase(blocks.begin() + se);
blocks.erase(blocks.begin() + fi);
blocks.push_back(q);
}
else{
if (blocks[fi].size() == 1)
blocks[fi].push_back(i);
else{
if (query({blocks[fi][0], i}) == 1)
reverse(blocks[fi].begin(), blocks[fi].end());
blocks[fi].push_back(i);
}
}
}
/* cout << "# " << i << " ------> \n";
for (auto it : blocks){
for (auto it2 : it)
cout << it2 << " ";
cout << '\n';
}
*/ }
Answer(blocks[0]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
252 KB |
# of queries: 1523 |
2 |
Correct |
20 ms |
256 KB |
# of queries: 1587 |
3 |
Correct |
17 ms |
408 KB |
# of queries: 1650 |
4 |
Correct |
18 ms |
332 KB |
# of queries: 1711 |
5 |
Correct |
23 ms |
384 KB |
# of queries: 1676 |
6 |
Correct |
23 ms |
256 KB |
# of queries: 1695 |
7 |
Correct |
18 ms |
324 KB |
# of queries: 1688 |
8 |
Correct |
21 ms |
256 KB |
# of queries: 1598 |
9 |
Correct |
31 ms |
256 KB |
# of queries: 1642 |
10 |
Correct |
14 ms |
256 KB |
# of queries: 934 |
11 |
Correct |
2 ms |
256 KB |
# of queries: 1 |
12 |
Correct |
2 ms |
384 KB |
# of queries: 2 |
13 |
Correct |
2 ms |
256 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
384 KB |
# of queries: 7 |
15 |
Correct |
2 ms |
256 KB |
# of queries: 56 |
16 |
Correct |
3 ms |
256 KB |
# of queries: 136 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
252 KB |
# of queries: 1523 |
2 |
Correct |
20 ms |
256 KB |
# of queries: 1587 |
3 |
Correct |
17 ms |
408 KB |
# of queries: 1650 |
4 |
Correct |
18 ms |
332 KB |
# of queries: 1711 |
5 |
Correct |
23 ms |
384 KB |
# of queries: 1676 |
6 |
Correct |
23 ms |
256 KB |
# of queries: 1695 |
7 |
Correct |
18 ms |
324 KB |
# of queries: 1688 |
8 |
Correct |
21 ms |
256 KB |
# of queries: 1598 |
9 |
Correct |
31 ms |
256 KB |
# of queries: 1642 |
10 |
Correct |
14 ms |
256 KB |
# of queries: 934 |
11 |
Correct |
2 ms |
256 KB |
# of queries: 1 |
12 |
Correct |
2 ms |
384 KB |
# of queries: 2 |
13 |
Correct |
2 ms |
256 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
384 KB |
# of queries: 7 |
15 |
Correct |
2 ms |
256 KB |
# of queries: 56 |
16 |
Correct |
3 ms |
256 KB |
# of queries: 136 |
17 |
Correct |
352 ms |
336 KB |
# of queries: 11409 |
18 |
Correct |
233 ms |
328 KB |
# of queries: 11228 |
19 |
Correct |
241 ms |
512 KB |
# of queries: 11108 |
20 |
Correct |
253 ms |
256 KB |
# of queries: 10390 |
21 |
Correct |
267 ms |
256 KB |
# of queries: 9953 |
22 |
Correct |
290 ms |
424 KB |
# of queries: 11174 |
23 |
Correct |
321 ms |
548 KB |
# of queries: 11328 |
24 |
Correct |
111 ms |
384 KB |
# of queries: 5203 |
25 |
Correct |
292 ms |
340 KB |
# of queries: 11090 |
26 |
Correct |
277 ms |
376 KB |
# of queries: 10279 |
27 |
Correct |
80 ms |
324 KB |
# of queries: 5042 |
28 |
Correct |
50 ms |
408 KB |
# of queries: 1998 |
29 |
Correct |
67 ms |
384 KB |
# of queries: 1996 |
30 |
Correct |
52 ms |
328 KB |
# of queries: 1998 |