이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const int N = 2e5 + 10 , M = 6e5 + 10;
int n , ar[N] , pos[N] , m , L[M] , R[M] , f[M] , s[M];
vector <pair<int , int>> vec;
bool Check(int mid)
{
for(int i = 0 ; i < mid ; i++)
swap(ar[L[i]] , ar[R[i]]);
for(int i = 0 ; i < n ; i++)
pos[ar[i]] = i;
vec.clear();
for(int i = 0 ; i < n ; i++) if(ar[i] != i)
{
int p = pos[i];
swap(ar[i] , ar[p]);
pos[ar[p]] = p;
pos[ar[i]] = i;
vec.push_back(make_pair(ar[i] , ar[p]));
}
return (vec.size() <= mid);
}
void Solve(int mid)
{
if(vec.size() < mid)
vec.push_back(make_pair(0 , 0));
for(int i = 0 ; i < mid ; i++)
{
swap(ar[L[i]] , ar[R[i]]);
swap(pos[ar[L[i]]] , pos[ar[R[i]]]);
f[i] = pos[vec[i].F];
s[i] = pos[vec[i].S];
swap(ar[f[i]] , ar[s[i]]);
swap(pos[ar[f[i]]] , pos[ar[s[i]]]);
}
}
int findSwapPairs(int nn, int S[], int mm, int X[], int Y[], int P[], int Q[]) {
n = nn;
m = mm;
for(int i = 0 ; i < m ; i++)
{
L[i] = X[i];
R[i] = Y[i];
}
int low = -1 , high = m;
while(high - low > 1)
{
for(int i = 0 ; i < n ; i++)
{
ar[i] = S[i];
pos[ar[i]] = i;
}
int mid = (low + high) >> 1;
if(Check(mid))
high = mid;
else
low = mid;
}
for(int i = 0 ; i < n ; i++)
{
ar[i] = S[i];
pos[ar[i]] = i;
}
Check(high);
for(int i = 0 ; i < n ; i++)
{
ar[i] = S[i];
pos[ar[i]] = i;
}
Solve(high);
for(int i = 0 ; i < m ; i++)
{
P[i] = f[i];
Q[i] = s[i];
}
return high;
}
컴파일 시 표준 에러 (stderr) 메시지
sorting.cpp: In function 'bool Check(int)':
sorting.cpp:28:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
28 | return (vec.size() <= mid);
| ~~~~~~~~~~~^~~~~~
sorting.cpp: In function 'void Solve(int)':
sorting.cpp:33:16: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
33 | if(vec.size() < mid)
| ~~~~~~~~~~~^~~~~
# | 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... |