From 4f92eb9f1ffd8c39db9706ef83ed0cbb68ada500 Mon Sep 17 00:00:00 2001 From: Segcolt Date: Sun, 5 Apr 2026 14:01:23 -0300 Subject: [PATCH] More problems --- .../A. The 67th Integer Problem.cpp | 108 +++++++++++ .../B. The 67th 6-7 Integer Problem.cpp | 115 ++++++++++++ .../C. The 67th Permutation Problem.cpp | 112 ++++++++++++ .../D. The 67th OEIS Problem.cpp | 129 +++++++++++++ .../E. The 67th XOR Problem.cpp | 117 ++++++++++++ .../F. The 67th Tree Problem.cpp | 148 +++++++++++++++ ...67th Iteration of \"Counting is Fun\".cpp" | 173 ++++++++++++++++++ .../D. Umka and a Long Flight.cpp | 165 +++++++++++++++++ .../E. Binary Search.cpp | 159 ++++++++++++++++ .../D. Funny Game.cpp | 157 ++++++++++++++++ .../C. Two Movies.cpp | 157 ++++++++++++++++ 11 files changed, 1540 insertions(+) create mode 100644 Codeforces Round 1090 (Div. 4)/A. The 67th Integer Problem.cpp create mode 100644 Codeforces Round 1090 (Div. 4)/B. The 67th 6-7 Integer Problem.cpp create mode 100644 Codeforces Round 1090 (Div. 4)/C. The 67th Permutation Problem.cpp create mode 100644 Codeforces Round 1090 (Div. 4)/D. The 67th OEIS Problem.cpp create mode 100644 Codeforces Round 1090 (Div. 4)/E. The 67th XOR Problem.cpp create mode 100644 Codeforces Round 1090 (Div. 4)/F. The 67th Tree Problem.cpp create mode 100644 "Codeforces Round 1090 (Div. 4)/G. The 67th Iteration of \"Counting is Fun\".cpp" create mode 100644 Codeforces Round 863 (Div. 3)/D. Umka and a Long Flight.cpp create mode 100644 Codeforces Round 935 (Div. 3)/E. Binary Search.cpp create mode 100644 Codeforces Round 959 sponsored by NEAR (Div. 1 + Div. 2)/D. Funny Game.cpp create mode 100644 Educational Codeforces Round 167 (Rated for Div. 2)/C. Two Movies.cpp diff --git a/Codeforces Round 1090 (Div. 4)/A. The 67th Integer Problem.cpp b/Codeforces Round 1090 (Div. 4)/A. The 67th Integer Problem.cpp new file mode 100644 index 0000000..c9582e9 --- /dev/null +++ b/Codeforces Round 1090 (Div. 4)/A. The 67th Integer Problem.cpp @@ -0,0 +1,108 @@ +/* Problem URL: https://codeforces.com/contest/2218/problem/A */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + ll x; + cin >> x; + cout << x << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 1090 (Div. 4)/B. The 67th 6-7 Integer Problem.cpp b/Codeforces Round 1090 (Div. 4)/B. The 67th 6-7 Integer Problem.cpp new file mode 100644 index 0000000..d7f4630 --- /dev/null +++ b/Codeforces Round 1090 (Div. 4)/B. The 67th 6-7 Integer Problem.cpp @@ -0,0 +1,115 @@ +/* Problem URL: https://codeforces.com/contest/2218/problem/B */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + vl a(7); + cin >> a; + + ll sum = accumulate(all(a), 0LL); + ll ans = -OO; + + rep(i, 7) { + rmax(ans, a[i] * 2 - sum); + } + cout << ans << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 1090 (Div. 4)/C. The 67th Permutation Problem.cpp b/Codeforces Round 1090 (Div. 4)/C. The 67th Permutation Problem.cpp new file mode 100644 index 0000000..bcf645f --- /dev/null +++ b/Codeforces Round 1090 (Div. 4)/C. The 67th Permutation Problem.cpp @@ -0,0 +1,112 @@ +/* Problem URL: https://codeforces.com/contest/2218/problem/C */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n; + cin >> n; + + rep(i, n) { + cout << i + 1 << ' ' << 3 * n - i * 2 - 1 << ' ' << 3 * n - i * 2 << ' '; + } + cout << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 1090 (Div. 4)/D. The 67th OEIS Problem.cpp b/Codeforces Round 1090 (Div. 4)/D. The 67th OEIS Problem.cpp new file mode 100644 index 0000000..a929fca --- /dev/null +++ b/Codeforces Round 1090 (Div. 4)/D. The 67th OEIS Problem.cpp @@ -0,0 +1,129 @@ +/* Problem URL: https://codeforces.com/contest/2218/problem/D */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + +constexpr int MAXN = 2e5 + 10; +bool isprime[MAXN]; +vl primes; + +void pre() +{ + fill(isprime, isprime + MAXN, true); + isprime[1] = false; + nrep(i, 2, MAXN) { + if (!isprime[i]) { + continue; + } + + primes.push_back(i); + + for (ll j = i * 2; j < MAXN; j += i) { + isprime[j] = false; + } + } +} + +#define TEST 1 + +void solve() +{ + int n; + cin >> n; + + vl ans(n); + rep(i, n) { + ans[i] = primes[i] * primes[i + 1]; + } + + cout << ans; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 1090 (Div. 4)/E. The 67th XOR Problem.cpp b/Codeforces Round 1090 (Div. 4)/E. The 67th XOR Problem.cpp new file mode 100644 index 0000000..6da0e86 --- /dev/null +++ b/Codeforces Round 1090 (Div. 4)/E. The 67th XOR Problem.cpp @@ -0,0 +1,117 @@ +/* Problem URL: https://codeforces.com/contest/2218/problem/E */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n; + cin >> n; + vl a(n); + cin >> a; + + ll ans = 0; + rep(i, n - 1) { + nrep(j, i + 1, n) { + rmax(ans, a[i] ^ a[j]); + } + } + cout << ans << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 1090 (Div. 4)/F. The 67th Tree Problem.cpp b/Codeforces Round 1090 (Div. 4)/F. The 67th Tree Problem.cpp new file mode 100644 index 0000000..59c020f --- /dev/null +++ b/Codeforces Round 1090 (Div. 4)/F. The 67th Tree Problem.cpp @@ -0,0 +1,148 @@ +/* Problem URL: https://codeforces.com/contest/2218/problem/F */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int x, y; + cin >> x >> y; + + int s = (x + y) & 1; + if (s & 1) { + if (y == 0) { + cout << "NO\n"; + return; + } + y--; + } else { + if (x == 0) { + cout << "NO\n"; + return; + } + x--; + } + + if (x > y) { + cout << "NO\n"; + return; + } + + cout << "YES\n"; + set ev; + rep(i, x + y) { + ev.insert(i + 1); + } + + V> ans; + auto it = ev.begin(); + while (x--) { + y--; + auto now = it; + it++; + cout << *it + 1 << ' ' << *now + 1 << '\n'; + ev.erase(now); + it++; + } + + repv(i, ev) { + cout << "1 " << i + 1 << '\n'; + } +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git "a/Codeforces Round 1090 (Div. 4)/G. The 67th Iteration of \"Counting is Fun\".cpp" "b/Codeforces Round 1090 (Div. 4)/G. The 67th Iteration of \"Counting is Fun\".cpp" new file mode 100644 index 0000000..650a6ea --- /dev/null +++ "b/Codeforces Round 1090 (Div. 4)/G. The 67th Iteration of \"Counting is Fun\".cpp" @@ -0,0 +1,173 @@ +/* Problem URL: https://codeforces.com/contest/2218/problem/G */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n, m; + cin >> n >> m; + + vi b(n); + cin >> b; + + if (n == 1) { + cout << "1\n"; + return; + } + + const ll mod = 676767677; + + vi pref(m + 1); + vvi ev(m); + + rep(i, n) { + pref[b[i] + 1]++; + ev[b[i]].push_back(i); + } + + ll ans = 1; + nrep(i, 1, m + 1) { + pref[i] += pref[i - 1]; + } + + auto fpow = [&](ll a, ll p) { + ll ans = 1; + rep(i, 61) { + if ((p >> i) & 1) { + (ans *= a) %= mod; + } + (a *= a) %= mod; + } + return ans; + }; + + nrep(i, 1, m) { + ll r = pref[i]; + ll l = pref[i - 1]; + ll d = r - l; + + repv(j, ev[i]) { + ll bf = OO; + if (j > 0) { + bf = b[j - 1]; + } + + ll af = OO; + if (j < n - 1) { + af = b[j + 1]; + } + + if (b[j] <= min(bf, af)) { + cout << "0\n"; + return; + } + + if (b[j] > min(bf, af) + 1) { + (ans *= d) %= mod; + continue; + } + + (ans *= r) %= mod; + } + } + + cout << ans << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 863 (Div. 3)/D. Umka and a Long Flight.cpp b/Codeforces Round 863 (Div. 3)/D. Umka and a Long Flight.cpp new file mode 100644 index 0000000..579bb62 --- /dev/null +++ b/Codeforces Round 863 (Div. 3)/D. Umka and a Long Flight.cpp @@ -0,0 +1,165 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1811/D */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + +constexpr int MAXN = 46; +ll fib[MAXN]; + +void pre() +{ + fib[0] = 1; + fib[1] = 1; + nrep(i, 2, MAXN) { + fib[i] = fib[i - 1] + fib[i - 2]; + } +} + +#define TEST 1 + +void solve() +{ + int n; + ll x, y; + cin >> n >> x >> y; + + ll h = fib[n]; + ll w = fib[n + 1]; + + ll hl = 1; + ll hr = h; + ll wl = 1; + ll wr = w; + + int now = 1; + int cur = n; + while (cur--) { + now ^= 1; + ll cost = fib[cur + 1]; + if (now) { + ll thr = hr - cost; + + if (hl <= x && thr >= x) { + hr = thr; + continue; + } + + ll thl = hl + cost; + if (thl <= x && hr >= x) { + hl = thl; + continue; + } + + cout << "NO\n"; + return; + } + + ll twr = wr - cost; + + if (wl <= y && twr >= y) { + wr = twr; + continue; + } + + ll twl = wl + cost; + + if (twl <= y && wr >= y) { + wl = twl; + continue; + } + + cout << "NO\n"; + return; + } + + cout << "YES\n"; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 935 (Div. 3)/E. Binary Search.cpp b/Codeforces Round 935 (Div. 3)/E. Binary Search.cpp new file mode 100644 index 0000000..da5ec2d --- /dev/null +++ b/Codeforces Round 935 (Div. 3)/E. Binary Search.cpp @@ -0,0 +1,159 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1945/E */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n, m; + cin >> n >> m; + + vi p(n); + cin >> p; + + set used; + int t = -1; + + int l = 1; + int r = n + 1; + while (r - l > 1) { + int mid = (l + r) >> 1; + used.insert(mid - 1); + if (p[mid - 1] == m) { + t = mid - 1; + } + + if (p[mid - 1] <= m) { + l = mid; + continue; + } + + r = mid; + } + + if (p[l - 1] == m) { + cout << "0\n"; + return; + } + + V> ans; + rep(i, n) { + if (p[i] == m) { + ans.emplace_back(i + 1, l); + break; + } + } + + if (t != -1) { + rep(i, n) { + if (used.count(i) || p[i] > m) { + continue; + } + + ans.emplace_back(i + 1, t + 1); + break; + } + } + + cout << ans.size() << '\n'; + repv(i, ans) { + cout << i.first << ' ' << i.second << '\n'; + } +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Codeforces Round 959 sponsored by NEAR (Div. 1 + Div. 2)/D. Funny Game.cpp b/Codeforces Round 959 sponsored by NEAR (Div. 1 + Div. 2)/D. Funny Game.cpp new file mode 100644 index 0000000..e41e44e --- /dev/null +++ b/Codeforces Round 959 sponsored by NEAR (Div. 1 + Div. 2)/D. Funny Game.cpp @@ -0,0 +1,157 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1994/D */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n; + cin >> n; + vl a(n); + cin >> a; + + vi dsu(n); + iota(all(dsu), 0); + + function find_p = [&](int i) { + if (i == dsu[i]) { + return i; + } + return dsu[i] = find_p(dsu[i]); + }; + + auto join = [&](int i, int j) { + i = find_p(i); + j = find_p(j); + + if (i == j) { + return false; + } + + dsu[j] = i; + return true; + }; + + V> ans; + + for (int i = n - 1; i > 0; i--) { + vi mod(i, -1); + rep(j, n) { + if (dsu[j] != j) { + continue; + } + + ll m = a[j] % i; + if (mod[m] != -1) { + ans.emplace_back(mod[m] + 1, j + 1); + join(mod[m], j); + break; + } + + mod[m] = j; + } + } + + reverse(all(ans)); + cout << "YES\n"; + repv(i, ans) { + cout << i.first << ' ' << i.second << '\n'; + } +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/Educational Codeforces Round 167 (Rated for Div. 2)/C. Two Movies.cpp b/Educational Codeforces Round 167 (Rated for Div. 2)/C. Two Movies.cpp new file mode 100644 index 0000000..8bb0bf2 --- /dev/null +++ b/Educational Codeforces Round 167 (Rated for Div. 2)/C. Two Movies.cpp @@ -0,0 +1,157 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1989/C */ + +#include +#include +#include + +using namespace std; +using namespace __gnu_pbds; + +template > +using ordered_set = tree; + +#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; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &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 +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +const int oo = INT32_MAX >> 1; +const ll OO = INT64_MAX >> 1; + + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + array c = {0, 0}; + int n; + cin >> n; + + int rm = 0; + int add = 0; + + vi a(n); + vi b(n); + cin >> a >> b; + rep(i, n) { + if (a[i] == b[i]) { + rm += a[i] == -1; + add += a[i] == 1; + continue; + } + + + if (a[i] == 1) { + c[0]++; + continue; + } + + if (b[i] == 1) { + c[1]++; + continue; + } + + if (a[i] == 0 || b[i] == 0) { + continue; + } + } + + while (rm > 0) { + if (c[0] > c[1]) { + c[0]--; + } else { + c[1]--; + } + rm--; + } + + while (add > 0) { + if (c[0] < c[1]) { + c[0]++; + } else { + c[1]++; + } + add--; + } + + cout << min(c[0], c[1]) << '\n'; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +}