QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#818543#8812. Library 3makrav#21 137ms4192kbC++203.5kb2024-12-17 21:46:452024-12-17 21:46:47

Judging History

你现在查看的是最新测评结果

  • [2024-12-17 21:46:47]
  • 评测
  • 测评结果:21
  • 用时:137ms
  • 内存:4192kb
  • [2024-12-17 21:46:45]
  • 提交

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);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 2
Accepted

Test #1:

score: 2
Accepted
time: 0ms
memory: 3940kb

input:

2
1

output:

? 1 0
! 0 1
-

result:

ok Accepted

Test #2:

score: 2
Accepted
time: 1ms
memory: 3872kb

input:

3
0

output:

? 1 2 0
! 1 2 0
-

result:

ok Accepted

Test #3:

score: 2
Accepted
time: 1ms
memory: 3868kb

input:

4
2
3
3
3
0

output:

? 1 3 0 2
? 3 1 0 2
? 0 3 1 2
? 2 3 0 1
? 1 2 3 0
! 1 2 3 0
-

result:

ok Accepted

Test #4:

score: 2
Accepted
time: 1ms
memory: 3796kb

input:

5
4
4
4
4
1
1
0

output:

? 1 4 0 2 3
? 2 4 1 0 3
? 1 2 4 0 3
? 1 4 3 0 2
? 1 0 2 3 4
? 3 1 2 0 4
? 3 0 2 1 4
! 3 0 2 1 4
-

result:

ok Accepted

Test #5:

score: 2
Accepted
time: 1ms
memory: 4132kb

input:

5
3
2
4
4
2
0

output:

? 1 4 0 2 3
? 4 1 0 2 3
? 0 4 1 2 3
? 2 4 0 1 3
? 3 4 0 2 1
? 3 1 2 0 4
! 3 1 2 0 4
-

result:

ok Accepted

Test #6:

score: 2
Accepted
time: 1ms
memory: 4100kb

input:

6
1
4
3
3
3
5
3
2
2
4
2

output:

? 1 4 5 2 3 0
? 2 1 3 5 0 4
? 1 2 3 5 0 4
? 3 1 2 5 0 4
? 5 1 3 2 0 4
? 0 1 3 5 2 4
? 4 1 3 5 0 2
? 4 1 3 2 0 5
? 2 4 3 1 0 5
? 2 1 4 3 0 5
? 4 2 5 1 0 3
! 1 4 5 2 0 3
-

result:

ok Accepted

Test #7:

score: 2
Accepted
time: 1ms
memory: 3844kb

input:

6
2
5
3
3
5
3
3
3
2

output:

? 1 4 5 2 3 0
? 2 1 3 5 0 4
? 3 2 1 5 0 4
? 2 5 1 3 0 4
? 2 0 1 5 3 4
? 2 4 1 5 0 3
? 4 2 0 5 1 3
? 2 5 0 4 1 3
? 5 4 0 3 1 2
! 3 4 0 2 1 5
-

result:

ok Accepted

Test #8:

score: 2
Accepted
time: 1ms
memory: 4072kb

input:

6
2
3
4
3
3
5
5
3
1
3

output:

? 1 4 5 2 3 0
? 2 1 3 5 0 4
? 0 5 4 2 3 1
? 5 0 4 2 3 1
? 4 5 0 2 3 1
? 2 5 4 0 3 1
? 3 5 4 2 0 1
? 1 5 4 2 3 0
? 4 0 5 3 2 1
? 1 0 4 3 2 5
! 4 1 5 3 2 0
-

result:

ok Accepted

Test #9:

score: 2
Accepted
time: 0ms
memory: 3844kb

input:

5
4
4
4
2
2

output:

? 1 4 0 2 3
? 2 4 1 0 3
? 1 2 4 0 3
? 1 4 3 0 2
? 0 1 3 4 2
! 4 0 3 1 2
-

result:

ok Accepted

Test #10:

score: 2
Accepted
time: 1ms
memory: 4128kb

input:

6
4
5
5
5
5
5
4
2
4
0

output:

? 1 4 5 2 3 0
? 4 1 5 2 3 0
? 5 4 1 2 3 0
? 2 4 5 1 3 0
? 3 4 5 2 1 0
? 0 4 5 2 3 1
? 1 5 3 2 4 0
? 1 4 3 5 2 0
? 1 4 3 2 0 5
? 1 3 0 5 2 4
! 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: 3872kb

input:

7
5
4
4
4
4
4
6
3
3
3
3
4
4
4
3
1

output:

? 1 4 6 2 3 0 5
? 4 1 6 2 3 0 5
? 6 4 1 2 3 0 5
? 2 4 6 1 3 0 5
? 3 4 6 2 1 0 5
? 0 4 6 2 3 1 5
? 5 4 6 2 3 0 1
? 2 4 1 6 3 0 5
? 1 2 4 6 3 0 5
? 1 4 3 6 2 0 5
? 1 4 0 6 3 2 5
? 4 2 1 6 3 0 5
? 3 4 1 6 2 0 5
? 0 4 1 6 3 2 5
? 2 1 0 6 3 4 5
? 2 4 0 6 1 3 5
! 2 0 4 6 1 3 5
-

result:

ok Accepted

Test #12:

score: 19
Accepted
time: 3ms
memory: 3848kb

input:

50
46
47
46
45
48
49
49
47
49
47
49
49
49
49
47
49
47
47
47
49
49
47
49
47
47
49
47
47
49
47
47
49
47
49
49
47
47
49
49
49
49
47
49
47
49
49
49
49
47
49
47
49
49
49
45
47
45
47
45
47
47
45
45
45
47
47
47
47
45
47
45
47
47
45
45
45
45
45
47
47
47
45
45
45
45
45
45
45
47
45
45
45
45
45
45
45
47
45
45
...

output:

? 48 49 25 43 28 0 13 18 29 33 41 26 16 5 11 47 17 39 27 20 40 2 23 14 38 15 45 1 24 32 42 34 9 10 37 22 3 7 30 31 12 36 35 46 21 8 44 6 19 4
? 39 26 43 45 7 21 5 1 0 42 37 44 23 34 31 38 33 14 20 13 36 4 3 6 24 29 12 17 18 35 2 8 15 30 32 28 11 9 40 22 49 46 19 41 25 10 47 16 48 27
? 46 44 16 40 15...

result:

ok Accepted

Test #13:

score: 19
Accepted
time: 0ms
memory: 3940kb

input:

98
92
91
96
95
95
95
95
95
95
95
95
95
95
95
95
95
95
95
97
95
97
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
95
95
95
95
95
95
95
97
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
...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 30 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 46 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73
? 95 13 12 55 ...

result:

ok Accepted

Test #14:

score: 19
Accepted
time: 2ms
memory: 3868kb

input:

98
92
95
90
93
94
95
92
91
92
95
94
95
88
93
96
97
95
95
95
97
97
95
95
97
95
95
97
97
97
95
97
95
97
95
97
95
95
97
95
95
97
95
97
97
95
97
95
97
95
97
95
97
95
95
95
97
95
95
97
97
95
95
95
95
95
95
95
97
97
97
97
95
95
97
95
95
97
95
97
97
97
97
97
95
97
97
97
97
95
95
97
97
95
97
97
95
95
97
95
...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 30 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 46 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73
? 95 13 12 55 ...

result:

ok Accepted

Test #15:

score: 19
Accepted
time: 5ms
memory: 4168kb

input:

99
92
92
98
96
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
96
98
96
98
96
98
98
98
98
98
98
98
98
96
98
98
96
98
98
98
98
98
98
96
98
98
98
98
98
98
96
98
96
98
98
98
96
98
96
98
96
98
96
96
96
98
98
98
98
98
98
98
96
96
98
98
98
98
98
98
98
98
96
98
96
98
98
98
98
98
98
98
98
98
98
96
98
96
98
98
...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 30 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46
? 36 92 20 ...

result:

ok Accepted

Test #16:

score: 19
Accepted
time: 5ms
memory: 4152kb

input:

99
94
94
94
96
94
94
94
94
94
96
96
94
94
96
94
94
96
94
92
94
96
94
90
94
94
96
96
96
90
96
94
96
94
94
94
94
96
94
92
94
96
96
94
92
94
92
90
94
94
94
94
94
94
94
96
94
94
92
94
94
94
92
92
92
94
96
94
94
96
94
94
90
92
88
92
90
92
94
92
94
92
92
92
96
94
96
96
92
90
96
94
92
94
94
96
96
96
94
96
...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 30 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46
? 36 92 20 ...

result:

ok Accepted

Test #17:

score: 19
Accepted
time: 4ms
memory: 3864kb

input:

99
92
94
92
94
92
94
96
94
92
94
92
92
94
94
96
92
96
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
98
96
96
98
98
96
98
98
96
98
98
98
98
98
98
98
96
98
96
96
98
96
98
98
98
98
98
96
98
98
96
98
98
98
98
98
98
96
98
96
96
96
98
98
96
98
98
98
96
98
96
98
98
98
98
96
98
96
98
98
96
98
98
98
98
98
98
...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 30 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46
? 36 92 20 ...

result:

ok Accepted

Test #18:

score: 19
Accepted
time: 2ms
memory: 3948kb

input:

100
97
98
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
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
97
97
97
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
97
97
97
97
97
97...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 99 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46 30
? 73 80 ...

result:

ok Accepted

Test #19:

score: 19
Accepted
time: 0ms
memory: 3824kb

input:

100
97
96
97
98
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
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
97
97
97
97...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 99 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46 30
? 73 80 ...

result:

ok Accepted

Test #20:

score: 19
Accepted
time: 2ms
memory: 4148kb

input:

100
96
95
96
97
96
95
94
95
94
95
96
95
96
95
94
95
96
95
96
93
94
95
96
93
94
95
98
97
97
99
97
97
97
99
99
97
97
99
97
97
97
97
97
97
97
97
97
97
97
97
99
97
97
97
97
97
97
99
97
97
97
97
99
97
97
97
97
97
97
97
97
97
99
97
97
97
97
97
97
97
97
97
99
97
97
97
97
97
97
99
97
97
97
99
99
97
97
97
97...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 99 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46 30
? 73 80 ...

result:

ok Accepted

Test #21:

score: 19
Accepted
time: 1ms
memory: 3888kb

input:

100
92
97
96
95
96
97
94
97
94
97
98
97
97
97
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
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97
97...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 99 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46 30
? 73 80 ...

result:

ok Accepted

Test #22:

score: 19
Accepted
time: 0ms
memory: 3872kb

input:

99
96
94
96
94
94
94
92
96
92
94
96
92
92
94
94
96
94
92
96
96
92
96
96
94
92
94
90
90
90
96
92
90
92
98
98
96
96
96
96
96
96
96
98
96
96
96
96
96
96
96
96
96
96
96
96
96
98
98
96
96
96
98
96
96
98
96
98
96
98
96
96
96
96
98
96
96
96
96
98
96
96
98
96
96
96
96
96
96
98
98
98
96
96
96
96
98
98
96
96
...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 30 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46
? 36 92 20 ...

result:

ok Accepted

Test #23:

score: 19
Accepted
time: 4ms
memory: 3960kb

input:

100
96
95
96
91
94
93
96
97
98
97
97
99
97
97
99
97
99
99
97
97
97
97
97
97
99
97
97
97
97
99
99
99
99
99
97
97
97
97
97
99
97
97
97
97
97
97
97
97
97
97
97
99
97
97
99
97
97
97
97
97
99
97
97
99
97
99
99
99
97
97
99
97
99
99
97
97
97
97
97
97
99
97
97
97
97
97
99
97
97
97
97
97
97
97
97
97
97
97
97...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 99 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46 30
? 73 80 ...

result:

ok Accepted

Test #24:

score: 19
Accepted
time: 7ms
memory: 3888kb

input:

100
94
93
92
95
94
91
98
97
99
97
97
99
99
99
99
99
99
97
97
97
97
99
99
97
97
97
99
97
99
97
97
97
97
97
99
99
99
97
97
97
99
97
97
99
97
97
99
97
99
97
99
97
97
97
99
97
97
99
97
97
99
99
97
99
97
99
99
97
97
97
97
99
97
97
99
99
99
99
99
97
99
97
99
99
99
99
97
97
97
97
99
97
99
97
97
99
97
97
97...

output:

? 84 93 25 88 28 0 89 18 29 97 41 92 63 5 11 47 55 77 27 68 40 79 56 80 38 15 45 1 24 32 75 34 85 60 37 22 3 7 99 31 53 36 35 94 81 8 44 6 19 4 90 96 83 62 16 17 23 43 82 14 86 67 69 54 91 87 59 65 72 74 98 51 20 33 12 42 2 39 64 50 66 21 57 78 48 9 10 76 58 13 61 26 95 49 71 52 70 73 46 30
? 73 80 ...

result:

ok Accepted

Subtask #3:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #25:

score: 0
Wrong Answer
time: 137ms
memory: 4192kb

input:

498
494
491
492
489
494
491
496
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
495
...

output:

? 240 469 388 242 272 376 21 446 114 358 309 282 149 142 303 241 493 281 438 107 478 156 296 424 481 210 200 239 331 226 355 333 26 169 152 322 443 235 407 291 132 301 68 400 262 318 124 108 426 432 54 228 0 401 70 342 133 494 217 105 74 162 223 323 335 192 106 491 117 100 496 14 377 136 48 417 224 ...

result:

wrong answer Wrong Answer [4]