이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=1, 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]]]);
while (cur<=n && b[cur]==d[cur])
cur++;
}
else
p[i]=q[i]=0;
}
return l;
}
# | 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... |