QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#125018 | #2789. Sorting | somethingnew# | 0 | 0ms | 0kb | C++20 | 2.1kb | 2023-07-15 22:44:21 | 2024-07-04 00:42:30 |
Judging History
answer
// ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
// ➡ @roadfromroi ⬅
// ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#include "sorting.h"
#define all(x) x.begin(), x.end()
using namespace std;
vector<pair<int, int>> numswp(vector<int> a) {
set<int> beba;
for (int i = 0; i < a.size(); ++i) {
if (a[i] != i)
beba.insert(i);
}
vector<pair<int, int>> swps;
while (!beba.empty()) {
int v = *beba.begin();
int u = a[v];
if (v != u)
swps.push_back({a[v], a[u]});
swap(a[v], a[u]);
}
if (!is_sorted(all(a))) exit(1);
return swps;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
vector<int> astrt(N);
for (int i = 0; i < N; ++i) {
astrt[i] = S[i];
}
int l = -1, r = M;
while (l + 1 < r) {
int m = l + r >> 1;
vector<int> beba = astrt;
for (int i = 0; i < m; ++i) {
swap(beba[X[i]], beba[Y[i]]);
}
if (numswp(beba).size() <= m)
r = m;
}
int m = l + r >> 1;
vector<int> beba = astrt;
for (int i = 0; i < m; ++i) {
swap(beba[X[i]], beba[Y[i]]);
}
vector<pair<int, int>> swp = numswp(beba);
if (beba.size() > r)
exit(1);
beba = astrt;
vector<int> ind(N);
for (int i = 0; i < N; ++i) {
ind[beba[i]] = i;
}
for (int i = 0; i < swp.size(); ++i) {
swap(ind[beba[X[i]]], ind[beba[Y[i]]]);
swap(beba[X[i]], beba[Y[i]]);
P[i] = ind[swp[i].first];
Q[i] = ind[swp[i].second];
swap(beba[P[i]], beba[Q[i]]);
swap(ind[swp[i].first], ind[swp[i].second]);
}
for (int i = swp.size(); i < r; ++i) {
swap(ind[beba[X[i]]], ind[beba[Y[i]]]);
swap(beba[X[i]], beba[Y[i]]);
P[i] = 0;
Q[i] = 0;
}
if (!is_sorted(all(beba)))
exit(1);
return r;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1 0 1 0 0
output:
Unauthorized output
result:
Subtask #2:
score: 0
Runtime Error
Test #8:
score: 0
Runtime Error
input:
1 0 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
Unauthorized output
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #13:
score: 0
Time Limit Exceeded
input:
2 0 1 60 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
output:
Unauthorized output
result:
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #28:
score: 0
Time Limit Exceeded
input:
1800 530 1775 466 953 230 1179 944 752 990 1316 275 1029 158 152 1673 1706 172 115 599 1661 131 699 1112 454 551 1059 291 495 28 67 773 480 839 462 1210 757 879 285 439 3 1429 820 26 1023 942 199 356 625 1705 1421 144 1529 716 7 1485 1027 1599 696 517 1353 456 1389 273 1363 1414 1177 718 41 777 1621...
output:
Unauthorized output
result:
Subtask #6:
score: 0
Skipped
Dependency #5:
0%