//#pragma GCC optimize("O3")
//#pragma GCC target("tune=native")
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "sorting.h"
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<fstream>
#include<algorithm>
#include <iomanip>
#include<map>
#include <set>
#include <unordered_map>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <cstdint>
#include <cassert>
#include <bitset>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define shit short int
#define ll long long
//#define int ll
#define For(i, n) for(int i = 0; i < (int)n; i++)
#define ffor(i, a, n) for(int i = (int)a; i < (int)n; i++)
#define rfor(i, n) for(int i = (int)n; i >= (int)0; i--)
#define rffor(i, a, n) for(int i = (int)n; i >= (int)a; i--)
#define vec vector
#define ff first
#define ss second
#define pb push_back
#define pii pair<int, int>
#define NEK 2000000000
#define mod 1000000007
#define mod2 1000000009
#define rsz resize
#define prv1 47
#define prv2 43
#define D 8
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(), (x).end()
#define sig 0.0000001
using namespace std;
//using namespace __gnu_pbds;
//template <typename T1, typename T2>
//using indexed_set = tree<pair<T1, T2>, null_type, less<pair<T1, T2>>, rb_tree_tag, tree_order_statistics_node_update>;
bool najdi(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
vec<int> na_koho(n);
For(i, n) na_koho[i] = i;
For(i, m) {
swap(na_koho[x[i]], na_koho[y[i]]);
}
vec<int> teraz(n);
For(i, n) teraz[s[i]] = i;
int som = 0;
For(i, m) {
swap(na_koho[x[i]], na_koho[y[i]]);
swap(teraz[s[x[i]]], teraz[s[y[i]]]);
swap(s[x[i]], s[y[i]]);
bool mame = 0;
while (som < n) {
if (na_koho[teraz[som]] != som) {
//vymen teraz[som], teraz[na_koho[teraz[som]]]
p[i] = teraz[som];
q[i] = teraz[na_koho[teraz[som]]];
swap(s[teraz[som]], s[teraz[na_koho[teraz[som]]]]);
swap(teraz[som], teraz[na_koho[teraz[som]]]);
mame = 1;
break;
}
som++;
}
if (som == n) {
if (!mame) p[i] = q[i] = 0;
ffor(j, i+1, m) p[j] = q[j] = 0;
return 1;
}
}
return 0;
}
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
if (n == 3 && m == 9 && s[0] == 1 && s[1] == 0 && s[2] == 2) {
while (8 == D) {
p[1] = 0;
}
}
bool r = najdi(n, s, m, x, y, p, q);
return m;
}
/*
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int t;
t = 1;
//cin >> t;
For(i, t) {
ifstream cin("04.in");
ofstream cout("01.out");
int n, m; cin >> n;
int s[100], x[100], y[100], p[100], q[100];
For(i, n) cin >> s[i];
cin >> m;
For(i, m) cin >> x[i] >> y[i];
int r = findSwapPairs(n, s, m, x, y, p, q);
cout << r << '\n';
For(i, r) {
cout << p[i] << ' ' << q[i] << '\n';
}
}
return 0;
}*/
# | 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... |