# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140561 | SirCeness | Sorting (IOI15_sorting) | C++14 | 1062 ms | 10936 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "sorting.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define orta ((l+r)>>1)
#define INF 1000000009
#define mod 1000000007
#define ppair(x) "(" << x.first << ", " << x.second << ") "
#define bas(x) #x << ": " << x << " "
#define prarr(x, n); cerr << #x << ": "; for(int qsd = 0; qsd < n; qsd++) cerr << x[qsd] << " "; cerr << "\n";
#define prarrv(x); cerr << #x << ": "; for(int qsd = 0; qsd < (int)x.size(); qsd++) cerr << x[qsd] << " "; cerr << "\n";
using namespace std;
typedef long long ll;
int n, m;
int dene(int N, int S[], int M, int X[], int Y[], int P[], int Q[]){
n = N; m = M;
vector<int> sanal;
for (int i = 0; i < n; i++) sanal.pb(S[i]);
for (int i = 0; i < m; i++) swap(sanal[X[i]], sanal[Y[i]]);
vector<int> sim;
for (int i = 0; i < n; i++) sim.pb(S[i]);
//prarrv(sanal);
vector<int> yer(n);
for (int i = 0; i < n; i++) yer[sanal[i]] = i;
vector<pair<int, int> > deg;
for (int i = 0; i < n; i++){
if (sanal[i] != i){
int j = yer[i];
yer[sanal[i]] = j;
deg.pb(mp(sanal[i], sanal[j]));
swap(sanal[i], sanal[j]);
}
}
//for (int i = 0; i < deg.size(); i++) cout << ppair(deg[i]) << " "; cout << endl;
int r = deg.size();
if (r > m) return 0;
return 1;
}
void yap(int N, int S[], int M, int X[], int Y[], int P[], int Q[]){
n = N; m = M;
vector<int> sanal;
for (int i = 0; i < n; i++) sanal.pb(S[i]);
for (int i = 0; i < m; i++) swap(sanal[X[i]], sanal[Y[i]]);
vector<int> sim;
for (int i = 0; i < n; i++) sim.pb(S[i]);
//prarrv(sanal);
vector<int> yer(n);
for (int i = 0; i < n; i++) yer[sanal[i]] = i;
vector<pair<int, int> > deg;
for (int i = 0; i < n; i++){
if (sanal[i] != i){
int j = yer[i];
yer[sanal[i]] = j;
deg.pb(mp(sanal[i], sanal[j]));
swap(sanal[i], sanal[j]);
}
}
//for (int i = 0; i < deg.size(); i++) cout << ppair(deg[i]) << " "; cout << endl;
int r = deg.size();
//if (r > m) return 0;
for (int i = 0; i < n; i++) yer[S[i]] = i;
for (int i = 0; i < M; i++){
swap(S[X[i]], S[Y[i]]);
if (i >= r){
P[i] = 0;
Q[i] = 0;
continue;
}
//P[i] = yer[deg[i].first];
//Q[i] = yer[deg[i].second];
for (int j = 0; j < n; j++){
if (S[j] == deg[i].first) P[i] = j;
if (S[j] == deg[i].second) Q[i] = j;
}
swap(S[P[i]], S[Q[i]]);
}
/*prarrv(sim);
for (int i = 0; i < m; i++){
swap(sim[X[i]], sim[Y[i]]);
prarrv(sim);
swap(sim[P[i]], sim[Q[i]]);
prarrv(sim);
}*/
//return 1;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int l = 0;
int r = M;
while (l < r){
int mid = (l+r)/2;
if (dene(N, S, mid, X, Y, P, Q)) r = mid;
else l = mid+1;
}
yap(N, S, l, X, Y, P, Q);
return l;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |