이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define ll long long
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
ll l = 0, h = M;
while(l < h){
int m = (l + h) / 2;
int s[N], slc[N];
FOR(i, 0, N - 1) s[i] = i;
for(int i = m - 1; i >= 0; i--){
swap(s[X[i]], s[Y[i]]);
}
FOR(i, 0, N - 1) slc[s[i]] = i;
queue<int> q;
int s2[N], lc[N];
FOR(i, 0, N - 1) s2[i] = S[i], lc[S[i]] = i;
FOR(i, 0, N - 1) if(slc[i] != lc[i]) q.push(i);
FOR(i, 0, m - 1){
swap(s[X[i]], s[Y[i]]), swap(slc[s[X[i]]], slc[s[Y[i]]]);
swap(s2[X[i]], s2[Y[i]]), swap(lc[s2[X[i]]], lc[s2[Y[i]]]);
while(q.size() && slc[q.front()] == lc[q.front()]){
q.pop();
}
if(q.size()){
int qi = q.front(); q.pop();
P[i] = slc[qi];
Q[i] = lc[qi];
swap(s2[P[i]], s2[Q[i]]), swap(lc[s2[P[i]]], lc[s2[Q[i]]]);
}else{
P[i] = Q[i] = 0;
}
}
FOR(i, 0, N - 1) if(s[i] != s2[i]) {
l = m + 1;
goto spot1;
}
h = m;
spot1:;
}
// fdasfd
int m = l;
int s[N], slc[N];
FOR(i, 0, N - 1) s[i] = i;
for(int i = m - 1; i >= 0; i--){
swap(s[X[i]], s[Y[i]]);
}
FOR(i, 0, N - 1) slc[s[i]] = i;
queue<int> q;
int s2[N], lc[N];
FOR(i, 0, N - 1) s2[i] = S[i], lc[S[i]] = i;
FOR(i, 0, N - 1) if(slc[i] != lc[i]) q.push(i);
FOR(i, 0, m - 1){
swap(s[X[i]], s[Y[i]]), swap(slc[s[X[i]]], slc[s[Y[i]]]);
swap(s2[X[i]], s2[Y[i]]), swap(lc[s2[X[i]]], lc[s2[Y[i]]]);
while(q.size() && slc[q.front()] == lc[q.front()]){
q.pop();
}
if(q.size()){
int qi = q.front(); q.pop();
P[i] = slc[qi];
Q[i] = lc[qi];
swap(s2[P[i]], s2[Q[i]]), swap(lc[s2[P[i]]], lc[s2[Q[i]]]);
}else{
P[i] = Q[i] = 0;
}
}
return l;
}
컴파일 시 표준 에러 (stderr) 메시지
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:12:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
12 | int m = (l + h) / 2;
| ~~~~~~~~^~~
sorting.cpp:14:33: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
14 | FOR(i, 0, N - 1) s[i] = i;
| ^
sorting.cpp:18:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
18 | FOR(i, 0, N - 1) slc[s[i]] = i;
| ^
sorting.cpp:23:51: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
23 | FOR(i, 0, N - 1) s2[i] = S[i], lc[S[i]] = i;
| ^
sorting.cpp:24:53: warning: conversion from 'long long int' to 'std::queue<int>::value_type' {aka 'int'} may change value [-Wconversion]
24 | FOR(i, 0, N - 1) if(slc[i] != lc[i]) q.push(i);
| ^
sorting.cpp:52:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
52 | int m = l;
| ^
sorting.cpp:54:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
54 | FOR(i, 0, N - 1) s[i] = i;
| ^
sorting.cpp:58:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
58 | FOR(i, 0, N - 1) slc[s[i]] = i;
| ^
sorting.cpp:63:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
63 | FOR(i, 0, N - 1) s2[i] = S[i], lc[S[i]] = i;
| ^
sorting.cpp:64:49: warning: conversion from 'long long int' to 'std::queue<int>::value_type' {aka 'int'} may change value [-Wconversion]
64 | FOR(i, 0, N - 1) if(slc[i] != lc[i]) q.push(i);
| ^
sorting.cpp:83:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
83 | 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... |