#include "key.h"
#include <vector>
#include <algorithm>
#define pii pair<int,int>
using namespace std;
int in[1001],vis[1001];
vector<int> v[1001];
void EnsureKeyInfo(int N) {
int i,t=0;
int stamp = 0;
vector<int> hist[2];
for (i = 1; i <= N; ++i) {
TakeKey(i);
int cnt = Explore();
v[cnt].push_back(i);
}
for (auto x : v[1]) in[x] = x,hist[0].push_back(x);
for (i = 2; i <= N; ++i) {//i=lev
vector<int> cyc;
for(auto x:v[i]){
int l = 0, r = hist[t].size() - 1;
int p = -1;
while (l <= r) {
int m = (l+r)>>1;
int pred = 0; ++stamp;
for (int j = l; j <= m; ++j) {
int u = hist[t][j];
TakeKey(u);
while (stamp != vis[u]) {
++pred;
vis[u] = stamp;
u = in[u];
}
}
TakeKey(x);
int cnt = Explore();
if (cnt - pred == 1) p = m, r = m - 1;
else l = m + 1;
/*if (cnt - pred == 2) l = m + 1;
else p=m,r = m - 1;*/
}
if (p < 0) cyc.push_back(x);
else {
in[x] = hist[t][p];
hist[1-t].push_back(x);
}
}
vector<int> meta;
int root[1001] = { 0 };
for (auto x : cyc) {
if (meta.empty()) meta.push_back(x);
else {
int l = 0, r=meta.size() - 1;
int p = -1;
while (l <= r) {
int m=(l + r) >> 1;
int pred = 0;
for (int j = l; j <= m; ++j) TakeKey(meta[j]),pred+=i;
TakeKey(x);
int cnt = Explore();
if (cnt == pred) p = m, r = m - 1;
else l = m + 1;
}
if (p < 0) meta.push_back(x);
else {
in[x] = meta[p];
if (!root[p]) root[p] = meta[p];
meta[p] = x;
}
}
}
for (int j = 0; j < meta.size(); ++j) {
in[root[j]] = meta[j];
hist[1 - t].push_back(meta[j]);
}
hist[t].clear();
t = 1 - t;
//tog
}
//for (i = 1; i <= N; ++i) printf("%d\n",in[i]);
for (i = 1; i <= N; ++i) {
int x = i;
while (-i!=vis[x]) {
Report(i, x); vis[x] = -i;
x = in[x];
}
}
}
Compilation message
key.cpp: In function 'void EnsureKeyInfo(int)':
key.cpp:76:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < meta.size(); ++j) {
~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Correct |
3 ms |
896 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
3 ms |
768 KB |
Output is correct |
16 |
Correct |
3 ms |
768 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Correct |
3 ms |
896 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
3 ms |
768 KB |
Output is correct |
16 |
Correct |
3 ms |
768 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
18 |
Correct |
5 ms |
1664 KB |
Output is correct |
19 |
Correct |
4 ms |
1664 KB |
Output is correct |
20 |
Correct |
6 ms |
1792 KB |
Output is correct |
21 |
Correct |
5 ms |
1664 KB |
Output is correct |
22 |
Correct |
4 ms |
1664 KB |
Output is correct |
23 |
Correct |
8 ms |
2304 KB |
Output is correct |
24 |
Correct |
6 ms |
2384 KB |
Output is correct |
25 |
Correct |
7 ms |
2432 KB |
Output is correct |
26 |
Correct |
7 ms |
2304 KB |
Output is correct |
27 |
Correct |
6 ms |
2304 KB |
Output is correct |
28 |
Correct |
8 ms |
2432 KB |
Output is correct |
29 |
Correct |
7 ms |
2432 KB |
Output is correct |
30 |
Correct |
7 ms |
2432 KB |
Output is correct |
31 |
Correct |
10 ms |
2304 KB |
Output is correct |
32 |
Correct |
7 ms |
2432 KB |
Output is correct |
33 |
Correct |
8 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Correct |
3 ms |
896 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
3 ms |
768 KB |
Output is correct |
16 |
Correct |
3 ms |
768 KB |
Output is correct |
17 |
Correct |
3 ms |
768 KB |
Output is correct |
18 |
Correct |
5 ms |
1664 KB |
Output is correct |
19 |
Correct |
4 ms |
1664 KB |
Output is correct |
20 |
Correct |
6 ms |
1792 KB |
Output is correct |
21 |
Correct |
5 ms |
1664 KB |
Output is correct |
22 |
Correct |
4 ms |
1664 KB |
Output is correct |
23 |
Correct |
8 ms |
2304 KB |
Output is correct |
24 |
Correct |
6 ms |
2384 KB |
Output is correct |
25 |
Correct |
7 ms |
2432 KB |
Output is correct |
26 |
Correct |
7 ms |
2304 KB |
Output is correct |
27 |
Correct |
6 ms |
2304 KB |
Output is correct |
28 |
Correct |
8 ms |
2432 KB |
Output is correct |
29 |
Correct |
7 ms |
2432 KB |
Output is correct |
30 |
Correct |
7 ms |
2432 KB |
Output is correct |
31 |
Correct |
10 ms |
2304 KB |
Output is correct |
32 |
Correct |
7 ms |
2432 KB |
Output is correct |
33 |
Correct |
8 ms |
2304 KB |
Output is correct |
34 |
Correct |
12 ms |
3712 KB |
Output is correct |
35 |
Correct |
15 ms |
3728 KB |
Output is correct |
36 |
Correct |
22 ms |
3832 KB |
Output is correct |
37 |
Correct |
12 ms |
3712 KB |
Output is correct |
38 |
Correct |
13 ms |
3712 KB |
Output is correct |
39 |
Correct |
15 ms |
4352 KB |
Output is correct |
40 |
Correct |
13 ms |
4360 KB |
Output is correct |
41 |
Correct |
18 ms |
4352 KB |
Output is correct |
42 |
Correct |
16 ms |
4352 KB |
Output is correct |
43 |
Correct |
17 ms |
4480 KB |
Output is correct |
44 |
Correct |
21 ms |
4352 KB |
Output is correct |
45 |
Correct |
15 ms |
4352 KB |
Output is correct |
46 |
Correct |
17 ms |
4352 KB |
Output is correct |
47 |
Correct |
19 ms |
4472 KB |
Output is correct |
48 |
Correct |
17 ms |
4352 KB |
Output is correct |
49 |
Correct |
17 ms |
4352 KB |
Output is correct |