QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#818342 | #8812. Library 3 | makrav# | 21 | 124ms | 4128kb | C++20 | 3.5kb | 2024-12-17 18:54:08 | 2024-12-17 18:54:09 |
Judging History
answer
#include "library3.h"
#include <bits/stdc++.h>
#include <cassert>
#include <vector>
using namespace std;
#define pb push_back
#define sz(x) (int)(x).size()
mt19937 rnd(time(NULL));
template<typename T>
void shuf(vector<T>&x) {
for (int i = 1; i < x.size(); i++) {
swap(x[i], x[rnd() % i]);
}
}
void solve(int N) {
int n = N;
vector<int> Q(n);
for (int i = 0; i < n; i++) Q[i] = i;
int la, req = 0;
while (true) {
shuf(Q);
la = query(Q);
req++;
if (la == 0) {
answer(Q); return;
}
if (la >= n - 2) break;
}
//cout << req << endl;
vector<vector<int>> loops = {{0}};
if (la == n - 1) {
for (int i = 1; i < n; i++) loops.back().pb(i);
} else {
loops.pb({});
for (int i = 1; i < n; i++) {
swap(Q[0], Q[i]);
int na = query(Q);
if (na == 0) {
answer(Q);
return;
}
swap(Q[0], Q[i]);
if (na < la) {
loops[0].pb(i);
} else loops[1].pb(i);
}
}
// for (int u : Q) cout << u << ' ';
// cout << endl;
while (true) {
// cout << "iter\n";
// for (auto u : loops) {
// for (int v : u) cout << v << ' ';
// cout << endl;
// }
int sw = 0;
bool need = false;
int curind = -1;
vector<pair<int, int>> pos(sz(loops));
for (auto l : loops) {
curind++;
if (l.size() >= 2) {
need = true;
int ind1 = rnd() % sz(l);
int ind2 = (ind1 + 1 + rnd() % (sz(l) - 1)) % sz(l);
swap(Q[l[ind1]], Q[l[ind2]]);
pos[curind] = {ind1, ind2};
sw++;
}
}
if (!need) break;
int curans = la - sw;
//cout << "check " << curans << ' ' <<query(Q) << endl;
vector<vector<int>> newloops;
for (int i = 0; i < sz(loops); i++) {
if (loops[i].size() == 1) {
newloops.pb(loops[i]);
continue;
}
for (int j = 0; j < 2; j++) newloops.pb({});
newloops.back().pb(loops[i][pos[i].first]);
newloops[sz(newloops) - 2].pb(loops[i][pos[i].second]);
for (int j = 0; j < loops[i].size(); j++) {
if (j == pos[i].first || j == pos[i].second) continue;
// if (j == loops[i].size() - 1 && newloops[sz(newloops) - 2].empty()) {
// newloops[sz(newloops) - 2].pb(loops[i][j]);
// continue;
// }
// if (loops[i].size() == 2) {
// newloops[sz(newloops) - 2].pb(loops[i][j]);
// continue;
// }
swap(Q[loops[i][j]], Q[loops[i][pos[i].first]]);
int rs = query(Q);
if (rs == 0) {
answer(Q);
return;
}
if (rs < curans) {
newloops.back().pb(loops[i][j]);
} else {
newloops[sz(newloops) - 2].pb(loops[i][j]);
}
swap(Q[loops[i][j]], Q[loops[i][pos[i].first]]);
}
}
swap(loops, newloops);
la = curans;
}
answer(Q);
}
详细
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 1ms
memory: 4092kb
input:
2 1
output:
? 1 0 ! 0 1 -
result:
ok Accepted
Test #2:
score: 2
Accepted
time: 1ms
memory: 4100kb
input:
3 0
output:
? 1 2 0 ! 1 2 0 -
result:
ok Accepted
Test #3:
score: 2
Accepted
time: 1ms
memory: 4072kb
input:
4 2 3 1 1 2
output:
? 3 2 0 1 ? 2 3 0 1 ? 0 2 3 1 ? 1 2 0 3 ? 0 2 1 3 ! 1 2 3 0 -
result:
ok Accepted
Test #4:
score: 2
Accepted
time: 0ms
memory: 3804kb
input:
5 2 2 2 4 4 2 2 2
output:
? 3 2 0 4 1 ? 1 3 2 0 4 ? 2 4 3 1 0 ? 1 2 4 0 3 ? 0 2 4 3 1 ? 1 0 4 3 2 ? 1 2 0 3 4 ? 3 4 0 1 2 ! 3 0 2 1 4 -
result:
ok Accepted
Test #5:
score: 2
Accepted
time: 1ms
memory: 4100kb
input:
5 3 4 4 4 4 3 3 0
output:
? 3 2 0 4 1 ? 2 3 0 4 1 ? 0 2 3 4 1 ? 4 2 0 3 1 ? 1 2 0 4 3 ? 3 0 4 2 1 ? 3 0 1 4 2 ? 3 1 2 0 4 ! 3 1 2 0 4 -
result:
ok Accepted
Test #6:
score: 2
Accepted
time: 1ms
memory: 3720kb
input:
6 3 2 3 4 3 5 3 3 5 3 1
output:
? 3 2 0 4 5 1 ? 1 4 2 3 0 5 ? 4 2 5 1 3 0 ? 2 0 3 4 1 5 ? 0 2 3 4 1 5 ? 3 0 2 4 1 5 ? 4 0 3 2 1 5 ? 1 0 3 4 2 5 ? 5 0 3 4 1 2 ? 4 0 5 1 2 3 ? 2 4 5 1 0 3 ! 1 4 5 2 0 3 -
result:
ok Accepted
Test #7:
score: 2
Accepted
time: 1ms
memory: 3828kb
input:
6 2 3 4 3 5 3 3 5 3 1
output:
? 3 2 0 4 5 1 ? 1 4 2 3 0 5 ? 4 2 5 1 3 0 ? 2 4 5 1 3 0 ? 5 2 4 1 3 0 ? 1 2 5 4 3 0 ? 3 2 5 1 4 0 ? 0 2 5 1 3 4 ? 2 3 0 1 4 5 ? 4 3 0 2 1 5 ! 3 4 0 2 1 5 -
result:
ok Accepted
Test #8:
score: 2
Accepted
time: 1ms
memory: 3796kb
input:
6 4 5 5 3 5 5 3 3 2
output:
? 3 2 0 4 5 1 ? 2 3 0 4 5 1 ? 0 2 3 4 5 1 ? 4 2 0 3 5 1 ? 5 2 0 4 3 1 ? 1 2 0 4 5 3 ? 4 0 1 3 5 2 ? 4 5 0 3 1 2 ? 4 1 2 3 0 5 ! 4 1 5 3 2 0 -
result:
ok Accepted
Test #9:
score: 2
Accepted
time: 1ms
memory: 3848kb
input:
5 4 4 2 4 2
output:
? 3 2 0 4 1 ? 0 2 1 4 3 ? 3 0 1 4 2 ? 3 2 1 0 4 ? 1 0 4 3 2 ! 4 0 3 1 2 -
result:
ok Accepted
Test #10:
score: 2
Accepted
time: 1ms
memory: 4100kb
input:
6 4 3 5 3 3 3 2 4 2 2
output:
? 3 2 0 4 5 1 ? 2 3 0 4 5 1 ? 0 2 3 4 5 1 ? 4 2 0 3 5 1 ? 5 2 0 4 3 1 ? 1 2 0 4 5 3 ? 4 3 0 2 5 1 ? 3 5 0 2 4 1 ? 3 1 0 2 5 4 ? 4 1 0 5 2 3 ! 1 3 0 5 2 4 -
result:
ok Accepted
Subtask #2:
score: 19
Accepted
Dependency #1:
100%
Accepted
Test #11:
score: 19
Accepted
time: 1ms
memory: 3800kb
input:
7 5 4 6 6 4 4 4 4 4 4 1 1 2
output:
? 3 2 6 4 5 1 0 ? 2 3 6 4 5 1 0 ? 6 2 3 4 5 1 0 ? 4 2 6 3 5 1 0 ? 5 2 6 4 3 1 0 ? 1 2 6 4 5 3 0 ? 0 2 6 4 5 1 3 ? 5 3 4 6 2 1 0 ? 1 3 4 6 5 2 0 ? 0 3 4 6 5 1 2 ? 2 5 4 6 1 3 0 ? 2 3 4 6 1 0 5 ? 2 5 4 6 1 0 3 ! 2 0 4 6 1 3 5 -
result:
ok Accepted
Test #12:
score: 19
Accepted
time: 1ms
memory: 4108kb
input:
50 42 45 44 47 46 45 40 47 44 45 46 45 46 47 44 45 44 47 44 45 48 49 47 47 49 47 47 49 49 49 49 47 47 47 47 47 47 49 47 47 47 49 49 49 47 47 49 49 49 47 49 47 47 49 47 49 49 47 47 47 49 49 49 49 47 49 47 49 49 49 47 45 47 47 45 47 47 45 45 47 47 47 47 47 47 47 45 47 47 47 47 47 47 47 45 47 45 47 45 ...
output:
? 13 45 25 32 5 31 0 16 38 6 23 39 24 43 21 42 33 26 15 49 7 1 35 8 17 11 41 4 2 37 12 40 27 28 48 36 46 9 3 47 44 18 22 34 30 20 19 29 10 14 ? 8 31 45 3 18 12 23 39 35 48 44 36 5 24 26 47 9 25 7 29 10 11 1 42 6 20 43 13 19 27 40 41 32 46 22 33 38 34 21 17 14 30 49 2 16 0 15 37 28 4 ? 18 30 4 1 11 2...
result:
ok Accepted
Test #13:
score: 19
Accepted
time: 0ms
memory: 3852kb
input:
98 90 93 94 93 94 93 90 91 94 95 96 95 95 97 95 97 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 97 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 ...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 94 6 95 96 36 39 45 31 41 ? 15 20 54 21 ...
result:
ok Accepted
Test #14:
score: 19
Accepted
time: 7ms
memory: 3844kb
input:
98 92 93 90 89 94 95 94 95 92 93 92 93 92 95 92 93 92 93 92 93 92 95 94 93 92 93 92 91 94 93 96 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 97 95 95 95 95 95 95 95 95 95 ...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 94 6 95 96 36 39 45 31 41 ? 15 20 54 21 ...
result:
ok Accepted
Test #15:
score: 19
Accepted
time: 9ms
memory: 3840kb
input:
99 90 94 92 96 94 94 96 94 94 94 96 94 94 92 92 92 94 94 92 96 92 90 96 94 92 94 94 92 96 94 92 96 96 92 96 88 96 94 94 94 94 96 96 94 92 94 96 96 92 94 94 92 94 98 96 96 98 96 96 96 96 96 96 96 96 96 96 96 96 98 96 96 96 96 96 96 96 96 96 98 96 98 96 96 96 96 98 96 96 96 96 96 96 96 98 96 96 96 96 ...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 45 31 41 94 ? 19 37 72 ...
result:
ok Accepted
Test #16:
score: 19
Accepted
time: 5ms
memory: 3832kb
input:
99 94 92 94 94 96 96 96 96 96 92 96 96 94 94 92 96 94 94 96 94 96 92 94 92 96 94 94 96 92 94 94 96 94 96 94 94 92 96 96 92 94 92 94 94 96 90 92 90 94 92 92 92 94 90 92 94 96 96 94 98 96 96 98 96 96 98 96 98 96 98 96 98 98 96 96 96 96 98 96 96 98 98 96 96 96 98 98 96 96 96 96 98 96 96 96 96 96 96 98 ...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 45 31 41 94 ? 19 37 72 ...
result:
ok Accepted
Test #17:
score: 19
Accepted
time: 0ms
memory: 3820kb
input:
99 92 96 94 94 94 94 94 94 94 92 94 94 94 92 92 94 94 96 94 96 92 96 96 96 92 94 92 92 94 90 94 96 92 94 96 94 94 96 94 94 96 92 96 96 94 94 94 94 94 94 92 94 94 92 90 96 94 96 94 96 96 96 96 94 96 94 96 94 90 90 96 96 96 92 94 96 92 94 92 96 96 94 94 90 92 96 90 92 92 92 92 92 96 92 96 96 96 94 94 ...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 45 31 41 94 ? 19 37 72 ...
result:
ok Accepted
Test #18:
score: 19
Accepted
time: 6ms
memory: 3868kb
input:
100 95 96 91 94 99 97 97 97 97 97 97 97 97 97 97 99 97 97 97 99 97 97 99 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 97 97 99 99 97 97 97 97 97 97 99 97 99 97...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 99 31 41 94 45 ? 93 76 ...
result:
ok Accepted
Test #19:
score: 19
Accepted
time: 8ms
memory: 4096kb
input:
100 93 96 93 94 95 96 97 94 93 96 91 92 93 92 93 96 93 94 95 94 93 96 95 92 95 92 95 96 93 94 97 92 95 98 99 97 99 99 99 99 99 99 99 99 99 97 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 97 99 99 99 99 99 99 99 99 99 99 99 97 99 99 99 99 99 99 99 99 99 99 99 99 97 99 99 99 97 99 99 99 99 99...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 99 31 41 94 45 ? 93 76 ...
result:
ok Accepted
Test #20:
score: 19
Accepted
time: 5ms
memory: 4128kb
input:
100 96 97 94 91 94 95 96 97 94 93 94 97 94 91 96 95 96 95 98 97 99 97 97 97 97 97 99 97 99 97 97 97 97 97 97 99 97 97 97 97 97 99 97 99 97 97 99 97 97 97 97 97 97 97 99 99 97 97 97 97 97 97 97 97 97 99 99 97 97 97 97 97 99 97 97 99 97 99 97 97 97 97 97 97 97 99 97 97 99 97 97 97 97 99 99 97 99 97 97...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 99 31 41 94 45 ? 93 76 ...
result:
ok Accepted
Test #21:
score: 19
Accepted
time: 2ms
memory: 3844kb
input:
100 94 97 96 95 96 97 96 93 96 95 92 97 92 97 96 97 94 95 94 95 96 95 96 93 96 97 96 97 96 95 94 95 98 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 97 97 97 97 97 97 97 97 97 97 97 97 97 99 99 97 97 97 97 97 97 97 97 97 97 97 97 97...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 99 31 41 94 45 ? 93 76 ...
result:
ok Accepted
Test #22:
score: 19
Accepted
time: 3ms
memory: 3804kb
input:
99 94 94 94 90 94 94 92 94 94 94 96 90 94 94 94 94 92 92 94 94 98 96 98 96 96 96 98 96 96 98 98 96 98 96 96 96 98 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 98 98 96 96 96 96 98 96 96 98 96 98 96 96 98 96 98 98 96 96 96 96 96 96 96 96 96 98 96 96 96 98 98 96 96 96 96 98 96 98 96 98 96 98 98 96 96 ...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 45 31 41 94 ? 19 37 72 ...
result:
ok Accepted
Test #23:
score: 19
Accepted
time: 2ms
memory: 3880kb
input:
100 96 97 90 93 96 97 96 97 96 95 94 97 94 97 90 95 94 93 96 95 94 95 94 93 94 95 92 97 96 95 94 93 96 93 94 95 94 91 96 95 96 95 96 97 94 93 96 95 94 93 94 91 92 95 94 97 94 97 96 97 98 97 99 97 97 99 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 97 99 99 97 97 97 97 99 97 97 99 97 97 99 97 99 97 99...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 99 31 41 94 45 ? 93 76 ...
result:
ok Accepted
Test #24:
score: 19
Accepted
time: 5ms
memory: 3852kb
input:
100 94 97 94 95 94 97 94 93 96 93 98 99 99 99 99 97 99 97 97 99 99 99 99 99 99 97 99 99 99 99 99 99 97 99 99 99 99 99 97 99 99 99 99 99 99 99 99 99 99 99 99 97 99 99 99 97 99 99 99 97 99 99 99 97 99 99 97 99 99 99 99 99 99 99 99 99 99 99 99 97 99 99 99 99 99 99 99 99 99 99 97 99 97 99 97 99 99 99 99...
output:
? 13 70 25 32 5 53 0 16 38 90 23 89 59 43 21 42 77 71 82 73 50 51 35 8 17 85 97 4 2 69 80 63 27 61 48 66 76 9 3 83 54 52 22 34 30 20 84 29 10 72 7 1 64 92 44 91 47 28 11 24 93 57 56 40 87 67 75 18 37 68 55 26 14 49 60 74 46 88 79 58 12 86 15 81 19 78 62 65 33 98 6 95 96 36 39 99 31 41 94 45 ? 93 76 ...
result:
ok Accepted
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #25:
score: 0
Wrong Answer
time: 124ms
memory: 4112kb
input:
498 492 491 492 491 494 491 490 491 486 489 492 493 494 491 494 491 494 491 490 487 490 493 490 491 494 493 492 493 490 493 490 493 492 491 488 491 492 491 486 487 492 491 492 487 490 493 490 493 490 493 492 493 492 493 488 493 492 495 488 491 492 491 492 489 490 489 492 493 494 489 494 489 492 493 ...
output:
? 179 269 332 469 410 437 465 432 25 188 299 75 314 271 358 163 440 240 224 401 353 307 476 231 95 295 302 294 226 459 32 42 442 212 139 482 348 280 8 219 296 424 419 488 140 141 220 366 274 451 251 59 73 393 143 262 347 44 339 408 196 191 17 149 157 374 64 113 151 27 183 481 357 225 293 372 496 182...
result:
wrong answer Wrong Answer [4]