# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
958621 | 2024-04-06T07:56:57 Z | 12345678 | Sorting (IOI15_sorting) | C++17 | 2 ms | 2396 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int nx=2e5+5; int s[nx], rs[nx], loc[nx], idx[nx], ridx[nx], n; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; int l=0, r=N; while (l<=r) { int md=(l+r)/2, cur=0; for (int i=0; i<N; i++) idx[i]=i, ridx[i]=i, s[i]=S[i], rs[s[i]]=i; for (int i=md-1; i>=0; i--) swap(ridx[idx[X[i]]], ridx[idx[Y[i]]]), swap(idx[X[i]], idx[Y[i]]); for (int i=0; i<md; i++) { swap(ridx[idx[X[i]]], ridx[idx[Y[i]]]); swap(idx[X[i]], idx[Y[i]]); swap(rs[s[X[i]]], rs[s[Y[i]]]); swap(s[X[i]], s[Y[i]]); while (cur<N&&ridx[cur]==rs[cur]) cur++; if (cur<N) P[i]=ridx[cur], Q[i]=rs[cur], swap(rs[s[P[i]]], rs[s[Q[i]]]), swap(s[P[i]], s[Q[i]]), cur++; } while (cur<N&&ridx[cur]==rs[cur]) cur++; //for (int j=0; j<N; j++) cout<<"debug "<<j<<' '<<s[j]<<' '<<rs[j]<<' '<<idx[j]<<' '<<ridx[j]<<'\n'; //if (l==r) cout<<"here "<<l<<' '<<r<<' '<<md<<'\n'; if (l==r) return P[l-1]=Q[l-1]=0, l; if (cur<N) l=md+1; else r=md; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Incorrect | 2 ms | 2396 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Incorrect | 2 ms | 2396 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Incorrect | 2 ms | 2396 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2392 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2392 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |