# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
785460 | fatemetmhr | 정렬하기 (IOI15_sorting) | C++17 | 39 ms | 10660 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// ~ Be Name Khoda ~ //
#include "sorting.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn = 1e6 + 10;
const int maxn5 = 15000 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;
int n, a[maxn5], b[maxn5], x[maxn5], y[maxn5];
int mask[maxn5], rev[maxn5];
bool mark[maxn5], add = false;
vector <pair<int, int>> op;
int rt;
void dfs(int v){
mark[v] = true;
if(!mark[b[v]]){
//cout << "its " << v << ' ' << b[v] << endl;
if(add)
op.pb({rt, b[v]});
dfs(b[v]);
}
}
bool check(int m){
//cout << "hereeeeee " << m << endl;
memset(mark, false, sizeof mark);
for(int i = 0; i < n; i++){
b[i] = a[i];
}
for(int i = 0; i < m; i++)
swap(b[x[i]], b[y[i]]);
int ans = n;
for(int i = 0; i < n; i++) if(!mark[i]){
rt = i;
dfs(i);
ans--;
}
//cout << "in " << m << ' ' << pt << endl;
return ans <= m;
}
int findSwapPairs(int N, int A[], int m, int X[], int Y[], int p[], int q[]) {
n = N;
for(int i = 0; i < m; i++){
x[i] = X[i];
y[i] = Y[i];
if(x[i] > y[i])
swap(x[i], y[i]);
}
for(int i = 0; i < n; i++)
a[i] = A[i];
bool re = true;
for(int i = 1; i < n; i++)
re &= (a[i] > a[i - 1]);
if(re)
return 0;
int lo = -1, hi = m;
while(hi - lo > 1){
int mid = (hi + lo) >> 1;
if(check(mid))
hi = mid;
else
lo = mid;
}
add = true;
check(hi);
for(int i = 0; i < n; i++)
mask[i] = rev[i] = i;
for(int i = 0; i < hi; i++)
q[i] = p[i] = 0;
for(int i = hi - 1; i >= 0; i--){
if(op.size() > i){
p[i] = mask[op.back().fi];
q[i] = mask[op.back().se];
op.pop_back();
}
int a = rev[x[i]], b = rev[y[i]];
mask[a] = y[i];
mask[b] = x[i];
rev[x[i]] = b;
rev[y[i]] = a;
}
return hi;
}
컴파일 시 표준 에러 (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... |