Submission #670089

# Submission time Handle Problem Language Result Execution time Memory
670089 2022-12-08T05:16:28 Z Astrayt Sorting (IOI15_sorting) C++17
100 / 100
362 ms 19300 KB
#include <bits/stdc++.h>
using namespace std;
#define starburst ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int long long
#define pii pair<int,int>
#define pb push_back

int findSwapPairs(int N, int *S, int M, int *X, int *Y, int *P, int *Q){
    int lb = 0, rb = M;
    while(lb != rb){
        int mid = (lb + rb) / 2;
        vector<int> cur(N), end(N), curid(N), endid(N);
        for(int i = 0; i < N; ++i) cur[i] = end[i] = S[i], curid[S[i]] = endid[S[i]] = i;
        for(int i = 0; i < mid; ++i){
            int x = X[i], y = Y[i];
            endid[end[x]] = y, endid[end[y]] = x;
            swap(end[x], end[y]);
        }
        int j = N - 1;
        for(int i = mid - 1; i >= 0; --i){
            while(j >= 0 && end[j] == j) j--;
            if(j < 0) break;
            int id = mid - i - 1;
            int x = X[id], y = Y[id];
            swap(curid[cur[x]], curid[cur[y]]);
            swap(cur[x], cur[y]);
            int a = end[j], b = j;
            swap(curid[a], curid[b]);
            swap(endid[a], endid[b]);
            swap(cur[curid[a]], cur[curid[b]]);
            swap(end[endid[a]], end[endid[b]]);
        }
        while(j >= 0 && end[j] == j) j--;
        if(j < 0) rb = mid;
        else lb = mid + 1;
    }
    vector<int> cur(N), end(N), curid(N), endid(N);
    for(int i = 0; i < N; ++i) cur[i] = end[i] = S[i], curid[S[i]] = endid[S[i]] = i;
    for(int i = 0; i < lb; ++i){
        int x = X[i], y = Y[i];
        endid[end[x]] = y, endid[end[y]] = x;
        swap(end[x], end[y]);
    }
    int j = N - 1;
    for(int i = lb - 1; i >= 0; --i){
        while(j >= 0 && end[j] == j) j--;
        if(j < 0) break;
        int id = lb - i - 1;
        int x = X[id], y = Y[id];
        swap(curid[cur[x]], curid[cur[y]]);
        swap(cur[x], cur[y]);
        int a = end[j], b = j;
        P[id] = curid[a], Q[id] = curid[b];
        if(P[id] > Q[id]) swap(P[id], Q[id]);
        swap(curid[a], curid[b]);
        swap(endid[a], endid[b]);
        swap(cur[curid[a]], cur[curid[b]]);
        swap(end[endid[a]], end[endid[b]]);
    }
    return lb;
}

/*void solve(){
    int n; cin >> n;
    int S[n];
    for(int i = 0; i < n; ++i) cin >> S[i];
    int m; cin >> m;
    int X[m], Y[m], P[m], Q[m];
    fill(P, P + m + 1, 0);
    fill(Q, Q + m + 1, 0);
    for(int i = 0; i < m; ++i) cin >> X[i] >> Y[i];
    int R = findSwapPairs(n, S, m, X, Y, P, Q);
    cout << R << '\n';
    for(int i = 0; i < R; ++i) cout << P[i] << ' ' << Q[i] << '\n';
}

signed main(){
    starburst
    int t = 1; //cin >> t;
    while(t--) solve();
}*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 440 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 428 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 436 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 444 KB Output is correct
10 Correct 2 ms 372 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 436 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 436 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 444 KB Output is correct
10 Correct 2 ms 372 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 436 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 229 ms 16828 KB Output is correct
16 Correct 274 ms 17552 KB Output is correct
17 Correct 351 ms 18360 KB Output is correct
18 Correct 103 ms 16320 KB Output is correct
19 Correct 230 ms 18016 KB Output is correct
20 Correct 237 ms 18472 KB Output is correct
21 Correct 240 ms 18464 KB Output is correct
22 Correct 230 ms 13564 KB Output is correct
23 Correct 266 ms 18904 KB Output is correct
24 Correct 353 ms 18660 KB Output is correct
25 Correct 351 ms 18468 KB Output is correct
26 Correct 234 ms 18676 KB Output is correct
27 Correct 211 ms 18252 KB Output is correct
28 Correct 332 ms 18608 KB Output is correct
29 Correct 322 ms 18400 KB Output is correct
30 Correct 167 ms 17916 KB Output is correct
31 Correct 315 ms 18660 KB Output is correct
32 Correct 254 ms 18280 KB Output is correct
33 Correct 350 ms 18808 KB Output is correct
34 Correct 305 ms 18684 KB Output is correct
35 Correct 240 ms 17536 KB Output is correct
36 Correct 81 ms 17480 KB Output is correct
37 Correct 362 ms 19300 KB Output is correct
38 Correct 355 ms 18328 KB Output is correct
39 Correct 342 ms 18656 KB Output is correct