이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define MAXN 1000005
using namespace std;
typedef long long ll;
typedef pair < int , int > ii;
int n, m, f, a[MAXN], b[MAXN], x[MAXN], y[MAXN], yer[MAXN], p[MAXN], q[MAXN];
bool dene(int son){
// cout << son << " -> ";
for(int i = 1; i <= n; i++)
b[i] = i;
for(int i = son; i >= 1; i--)
swap(b[x[i]], b[y[i]]);
// for(int i = 1; i <= n; i++)cout << b[i] << " ";cout << endl;
for(int i = 1; i <= n; i++)
yer[a[i]] = i;
int su = 1;
for(int i = 1; i <= son; i++){
swap(a[x[i]], a[y[i]]);
swap(yer[a[x[i]]], yer[a[y[i]]]);
swap(b[x[i]], b[y[i]]);
while(su <= n and yer[su] == b[su])
su++;
if(su <= n){
// cout << yer[su] << " " << b[su] << endl;
p[i] = yer[su];
q[i] = b[su];
swap(a[p[i]], a[q[i]]);
swap(yer[a[p[i]]], yer[a[q[i]]]);
} else
p[i] = q[i] = 1;
}
// cout << son << " -> ";for(int i = 1; i <= n; i++)cout << a[i] << " ";cout << endl;
for(int i = 1; i <= n; i++)
if(a[i] != i)
return 0;
return 1;
}
int findSwapPairs(int nn, int S[], int M, int X[], int Y[], int P[], int Q[]) {n = nn;m = M;
for(int i = 1; i <= n; i++){
a[i] = S[i - 1] + 1;
if(a[i] != i)
f = 1;
}
if(!f)return 0;
for(int i = 1; i <= m; i++){
x[i] = X[i - 1] + 1;
y[i] = Y[i - 1] + 1;
}
int bas = 1, son = m;
while(bas < son){
for(int i = 1; i <= n; i++)a[i] = S[i - 1] + 1;
if(dene(orta))
son = orta;
else
bas = orta + 1;
}
for(int i = 1; i <= n; i++)a[i] = S[i - 1] + 1;
if(!dene(orta))assert(0);
for(int i = 1; i <= orta; i++){
P[i - 1] = p[i] - 1;
Q[i - 1] = q[i] - 1;
}
return orta;
}
# | 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... |