# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
587517 | benson1029 | 정렬하기 (IOI15_sorting) | C++14 | 1043 ms | 18596 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
int a[200005], b[200005], s[200005];
bool stexists[200005];
vector< pair<int,int> > v;
set<int> st;
void swapa(int x, int y) {
b[a[x]] = y;
b[a[y]] = x;
if(!stexists[x] && stexists[y]) {
st.erase(y);
st.insert(x);
}
else if(stexists[x] && !stexists[y]) {
st.erase(x);
st.insert(y);
}
swap(stexists[x], stexists[y]);
swap(a[x], a[y]);
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int l = 0, r = N, mid;
while(l <= r) {
mid = (l+r)/2;
for(int i=0; i<N; i++) {
a[i] = i;
s[i] = S[i];
}
for(int i=mid-1; i>=0; i--) {
swap(a[X[i]], a[Y[i]]);
}
st.clear();
for(int i=0; i<N; i++) {
stexists[i] = (a[i] != s[i]);
if(a[i] != s[i]) st.insert(i);
b[a[i]] = i;
}
v.clear();
for(int i=0; i<mid; i++) {
swapa(X[i], Y[i]);
swap(s[X[i]], s[Y[i]]);
if(!st.empty()) {
int j = *st.begin();
int k = b[s[j]];
swap(s[j], s[k]);
v.push_back({j, k});
if(s[j] == a[j]) {
st.erase(j);
stexists[j] = false;
}
if(s[k] == a[k]) {
st.erase(k);
stexists[k] = false;
}
} else v.push_back({0, 0});
}
if(l==r) {
for(int i=0; i<v.size(); i++) P[i] = v[i].first, Q[i] = v[i].second;
return v.size();
} else {
if(st.empty()) r = mid;
else l = mid+1;
}
}
}
컴파일 시 표준 에러 (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... |