Submission #572153

# Submission time Handle Problem Language Result Execution time Memory
572153 2022-06-03T19:24:25 Z Hanksburger Sorting (IOI15_sorting) C++17
100 / 100
419 ms 21852 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005], c[200005], d[200005];
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[])
{
    int l=0, r=m, mid, cur;
    while (l<r)
    {
        mid=(l+r)/2;
        for (int i=0; i<n; i++)
        {
            a[i]=b[i]=i;
            c[i]=s[i];
            d[s[i]]=i;
        }
        for (int i=mid-1; i>=0; i--)
        {
            swap(a[x[i]], a[y[i]]);
            swap(b[a[x[i]]], b[a[y[i]]]);
        }
        cur=0;
        for (int i=0; i<mid; i++)
        {
            swap(a[x[i]], a[y[i]]);
            swap(b[a[x[i]]], b[a[y[i]]]);
            swap(c[x[i]], c[y[i]]);
            swap(d[c[x[i]]], d[c[y[i]]]);
            while (cur<=n && b[cur]==d[cur])
                cur++;
            if (cur<n)
            {
                swap(c[b[cur]], c[d[cur]]);
                swap(d[c[b[cur]]], d[c[d[cur]]]);
            }
        }
        while (cur<=n && b[cur]==d[cur])
            cur++;
        if (cur<n)
            l=mid+1;
        else
            r=mid;
    }
    for (int i=0; i<n; i++)
    {
        a[i]=b[i]=i;
        c[i]=s[i];
        d[s[i]]=i;
    }
    for (int i=l-1; i>=0; i--)
    {
        swap(a[x[i]], a[y[i]]);
        swap(b[a[x[i]]], b[a[y[i]]]);
    }
    cur=0;
    for (int i=0; i<l; i++)
    {
        swap(a[x[i]], a[y[i]]);
        swap(b[a[x[i]]], b[a[y[i]]]);
        swap(c[x[i]], c[y[i]]);
        swap(d[c[x[i]]], d[c[y[i]]]);
        while (cur<=n && b[cur]==d[cur])
            cur++;
        if (cur<n)
        {
            p[i]=b[cur];
            q[i]=d[cur];
            swap(c[b[cur]], c[d[cur]]);
            swap(d[c[b[cur]]], d[c[d[cur]]]);
        }
        else
            p[i]=q[i]=0;
    }
    return l;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 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 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 564 KB Output is correct
24 Correct 2 ms 456 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 396 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 392 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 480 KB Output is correct
12 Correct 2 ms 472 KB Output is correct
13 Correct 2 ms 476 KB Output is correct
14 Correct 1 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 396 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 392 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 480 KB Output is correct
12 Correct 2 ms 472 KB Output is correct
13 Correct 2 ms 476 KB Output is correct
14 Correct 1 ms 476 KB Output is correct
15 Correct 230 ms 19296 KB Output is correct
16 Correct 296 ms 19664 KB Output is correct
17 Correct 403 ms 20820 KB Output is correct
18 Correct 99 ms 16240 KB Output is correct
19 Correct 275 ms 19204 KB Output is correct
20 Correct 273 ms 19780 KB Output is correct
21 Correct 219 ms 19780 KB Output is correct
22 Correct 218 ms 16088 KB Output is correct
23 Correct 258 ms 21580 KB Output is correct
24 Correct 384 ms 21328 KB Output is correct
25 Correct 375 ms 20976 KB Output is correct
26 Correct 267 ms 19752 KB Output is correct
27 Correct 236 ms 19096 KB Output is correct
28 Correct 400 ms 20992 KB Output is correct
29 Correct 379 ms 20536 KB Output is correct
30 Correct 194 ms 18516 KB Output is correct
31 Correct 380 ms 21024 KB Output is correct
32 Correct 268 ms 20840 KB Output is correct
33 Correct 419 ms 21228 KB Output is correct
34 Correct 334 ms 21116 KB Output is correct
35 Correct 268 ms 18864 KB Output is correct
36 Correct 67 ms 17460 KB Output is correct
37 Correct 414 ms 21852 KB Output is correct
38 Correct 411 ms 20928 KB Output is correct
39 Correct 390 ms 21136 KB Output is correct