Add a bunch of other problems.
Some are not finished...
This commit is contained in:
89
Codeforces Round 1034 (Div. 3)/A. Blackboard Game.cpp
Normal file
89
Codeforces Round 1034 (Div. 3)/A. Blackboard Game.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2123/problem/A */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
if (n % 4 == 0) {
|
||||
cout << "Bob\n";
|
||||
continue;
|
||||
}
|
||||
cout << "Alice\n";
|
||||
}
|
||||
}
|
||||
111
Codeforces Round 1034 (Div. 3)/B. Tournament.cpp
Normal file
111
Codeforces Round 1034 (Div. 3)/B. Tournament.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2123/problem/B */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n, j, k;
|
||||
cin >> n >> j >> k;
|
||||
j--;
|
||||
|
||||
vi fds(n);
|
||||
cin >> fds;
|
||||
|
||||
int lesser = 0;
|
||||
int greater = 0;
|
||||
|
||||
rep(i, n) {
|
||||
if (i == j) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fds[i] > fds[j]) {
|
||||
greater++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fds[i] <= fds[j]) {
|
||||
lesser++;
|
||||
}
|
||||
}
|
||||
|
||||
if (n - lesser - greater + (greater == 0 ? 0 : 1) <= k) {
|
||||
cout << "YES\n";
|
||||
} else {
|
||||
cout << "NO\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
153
Codeforces Round 1034 (Div. 3)/C. Prefix Min and Suffix Max.cpp
Normal file
153
Codeforces Round 1034 (Div. 3)/C. Prefix Min and Suffix Max.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2123/problem/C */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
vi fds(n);
|
||||
cin >> fds;
|
||||
|
||||
while (__builtin_popcount(fds.size()) != 1) {
|
||||
fds.push_back(0);
|
||||
}
|
||||
|
||||
auto comp = [&](pair<int, int> a, pair<int, int> b) {
|
||||
return make_pair(max(a.first, b.first), min(a.second, b.second));
|
||||
};
|
||||
|
||||
V<pair<int, int>> seg(fds.size() * 2);
|
||||
|
||||
for (int i = fds.size(); i < fds.size() * 2; i++) {
|
||||
seg[i] = {fds[i - fds.size()], fds[i - fds.size()]};
|
||||
}
|
||||
|
||||
for (int i = fds.size() - 1; i > 0; i--) {
|
||||
seg[i] = comp(seg[i * 2], seg[i * 2 + 1]);
|
||||
}
|
||||
|
||||
function<pair<int, int>(int, int, int, int, int)> search = [&](int i, int l, int r, int tl, int tr) -> pair<int, int> {
|
||||
if (l > tr || r < tl) {
|
||||
return {-1, 1e9};
|
||||
}
|
||||
|
||||
if (l >= tl && r <= tr) {
|
||||
return seg[i];
|
||||
}
|
||||
|
||||
int mid = (l + r) / 2;
|
||||
|
||||
return comp(search(i * 2, l, mid, tl, tr), search(i * 2 + 1, mid + 1, r, tl, tr));
|
||||
};
|
||||
|
||||
rep(i, n) {
|
||||
auto [lmax, lmin] = search(1, 0, fds.size() - 1, 0, i - 1);
|
||||
auto [rmax, rmin] = search(1, 0, fds.size() - 1, i + 1, n - 1);
|
||||
|
||||
int now = fds[i];
|
||||
|
||||
if (now < lmin && now < rmin) {
|
||||
cout << "1";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now > lmax && now > rmax) {
|
||||
cout << "1";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now < rmax && now < lmin) {
|
||||
cout << "1";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now > rmax && now > lmin) {
|
||||
cout << "1";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now > rmax && now < lmin) {
|
||||
cout << "1";
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << "0";
|
||||
}
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
98
Codeforces Round 1034 (Div. 3)/D. Binary String Battle.cpp
Normal file
98
Codeforces Round 1034 (Div. 3)/D. Binary String Battle.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2123/problem/D */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n, k;
|
||||
string a;
|
||||
cin >> n >> k >> a;
|
||||
|
||||
int ones = 0;
|
||||
repv(i, a) {
|
||||
if (i == '1') {
|
||||
ones++;
|
||||
}
|
||||
}
|
||||
|
||||
if (ones <= k || n / 2 + 1 <= k) {
|
||||
cout << "Alice\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << "Bob\n";
|
||||
}
|
||||
}
|
||||
128
Codeforces Round 1034 (Div. 3)/E. MEX Count.cpp
Normal file
128
Codeforces Round 1034 (Div. 3)/E. MEX Count.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2123/problem/E */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
vi a(n);
|
||||
cin >> a;
|
||||
|
||||
vi count(n + 2);
|
||||
rep(i, n) {
|
||||
count[a[i]]++;
|
||||
}
|
||||
|
||||
vi pref(n + 3);
|
||||
pref[0] = count[0] - 1;
|
||||
|
||||
vi suf(n + 3);
|
||||
suf[n] = count[n];
|
||||
|
||||
nrep(i, 1, n + 1) {
|
||||
pref[i] = pref[i - 1] + count[i] - 1;
|
||||
suf[n - i] = suf[n - i + 1] + count[n - i];
|
||||
}
|
||||
|
||||
int first = 0;
|
||||
while (count[first] > 0) {
|
||||
first++;
|
||||
}
|
||||
|
||||
vi ans(n + 1);
|
||||
|
||||
for (int i = first; i >= 0; i--) {
|
||||
int low = count[i];
|
||||
int high = pref[i] + 2 + suf[i + 1];
|
||||
|
||||
ans[low]++;
|
||||
if (high > n) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ans[high]--;
|
||||
}
|
||||
|
||||
cout << "1";
|
||||
nrep(i, 1, n + 1) {
|
||||
ans[i] += ans[i - 1];
|
||||
cout << ' ' << ans[i];
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
126
Codeforces Round 1034 (Div. 3)/F. Minimize Fixed Points.cpp
Normal file
126
Codeforces Round 1034 (Div. 3)/F. Minimize Fixed Points.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2123/problem/F */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
vi div(1e5 + 1);
|
||||
rep(i, 1e5 + 1) {
|
||||
div[i] = i;
|
||||
}
|
||||
|
||||
vi primes(1e5 + 1);
|
||||
|
||||
for (int i = 2; i <= 1e5; i++) {
|
||||
if (div[i] != i) {
|
||||
continue;
|
||||
}
|
||||
|
||||
primes.push_back(i);
|
||||
|
||||
for (int j = i * 2; j <= 1e5; j += i) {
|
||||
div[j] = i;
|
||||
}
|
||||
}
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
vi fds(n);
|
||||
vi pos(n + 1);
|
||||
rep(i, n) {
|
||||
fds[i] = i + 1;
|
||||
pos[i + 1] = i;
|
||||
}
|
||||
|
||||
nrep(i, 1, n) {
|
||||
if (div[fds[i]] == fds[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int now = i;
|
||||
int change = pos[div[fds[i]]];
|
||||
|
||||
int num1 = fds[i];
|
||||
int num2 = fds[pos[div[fds[i]]]];
|
||||
|
||||
swap(fds[now], fds[change]);
|
||||
swap(pos[num1], pos[num2]);
|
||||
}
|
||||
|
||||
cout << fds;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user