#include "sorting.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(a...) qqbx(#a, a)
#define pary(a...) danb(#a, a)
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
template <typename ...T> void qqbx(const char *s, T ...a) {
int cnt = sizeof...(T);
((std::cerr << "\e[1;32m(" << s << ") = ("), ..., (std::cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
std::cerr << "\e[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
std::cerr << (f++ ? ", " : "") << *L;
std::cerr << " ]\e[0m\n";
}
#else
#define debug(...) ((void)0)
#define pary(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
using namespace std;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
vector<int> targ(N);
for (int i = 0; i < N; i++) targ[i] = i;
for (int i = M-1; i >= 0; i--)
swap(targ[X[i]], targ[Y[i]]);
vector<int> s(S, S+N);
vector<int> pos(N);
for (int i = 0; i < N; i++)
pos[s[i]] = i;
vector<pair<int,int>> ans;
for (int i = 0; i < N; i++) {
{
int a = X[i], b = Y[i];
swap(targ[a], targ[b]);
swap(pos[s[a]], pos[s[b]]);
swap(s[a], s[b]);
}
{
int a = pos[i];
int b = pos[targ[a]];
swap(pos[s[a]], pos[s[b]]);
swap(s[a], s[b]);
ans.emplace_back(a, b);
}
}
for (int i = N; i < M; i++) {
ans.emplace_back(0, 0);
{
int a = X[i], b = Y[i];
swap(targ[a], targ[b]);
swap(pos[s[a]], pos[s[b]]);
swap(s[a], s[b]);
}
}
pary(all(s));
for (size_t i = 0; i < ans.size(); i++)
tie(P[i], Q[i]) = ans[i];
return ans.size();
}
Compilation message
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:63:20: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
63 | return ans.size();
| ~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |