From 704b6fec602a92961c0572c3a28a987681c33d23 Mon Sep 17 00:00:00 2001 From: Segcolt Date: Wed, 8 Apr 2026 14:42:50 -0300 Subject: [PATCH 1/3] More stuff --- .../C. DIY.cpp | 130 ++++++++++++ .../G. Guess One Character.cpp | 131 ++++++++++++ .../A. The Equalizer.cpp | 121 +++++++++++ .../B. Flip the Bit (Easy Version).cpp | 126 +++++++++++ .../C. Grid Covering.cpp | 114 ++++++++++ .../F. Rudolf and Imbalance.cpp | 193 +++++++++++++++++ .../C. Minimizing the Sum.cpp | 148 +++++++++++++ Hello 2024/C. Grouping Increases.cpp | 134 ++++++++++++ .../D. Darius' Wisdom.cpp | 200 ++++++++++++++++++ .../C. Remove the Bracket.cpp | 139 ++++++++++++ problemlist.md | 9 + 11 files changed, 1445 insertions(+) create mode 100644 2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/C. DIY.cpp create mode 100644 2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/G. Guess One Character.cpp create mode 100644 Codeforces Round 1091 (Div. 2) and CodeCraft 26/A. The Equalizer.cpp create mode 100644 Codeforces Round 1091 (Div. 2) and CodeCraft 26/B. Flip the Bit (Easy Version).cpp create mode 100644 Codeforces Round 1091 (Div. 2) and CodeCraft 26/C. Grid Covering.cpp create mode 100644 Codeforces Round 933 (Div. 3)/F. Rudolf and Imbalance.cpp create mode 100644 Educational Codeforces Round 165 (Rated for Div. 2)/C. Minimizing the Sum.cpp create mode 100644 Hello 2024/C. Grouping Increases.cpp create mode 100644 Rayan Programming Contest 2024 - Selection (Codeforces Round 989, Div. 1 + Div. 2)/D. Darius' Wisdom.cpp create mode 100644 TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!)/C. Remove the Bracket.cpp diff --git a/2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/C. DIY.cpp b/2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/C. DIY.cpp new file mode 100644 index 0000000..9ace9b0 --- /dev/null +++ b/2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/C. DIY.cpp @@ -0,0 +1,130 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2038/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; + + map c; + rep(i, n) { + ll x; + cin >> x; + c[x]++; + } + + vi a; + repv(i, c) { + i.second -= (i.second & 1); + while (i.second--) { + a.push_back(i.first); + } + } + + if (a.size() < 8) { + cout << "NO\n"; + return; + } + + cout << "YES\n"; + cout << a[0] << ' ' << a[2] << ' ' << a[1] << ' ' << a[a.size() - 1] << ' ' << a[a.size() - 3] << ' ' << a[2] << ' ' << a[a.size() - 3] << ' ' << a[a.size() - 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/2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/G. Guess One Character.cpp b/2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/G. Guess One Character.cpp new file mode 100644 index 0000000..4237a50 --- /dev/null +++ b/2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/G. Guess One Character.cpp @@ -0,0 +1,131 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2038/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; + cin >> n; + + auto ask = [&](string c) { + cout << "1 " << c << endl; + int ans; + cin >> ans; + return ans; + }; + + auto answer = [&](int i, int c) { + cout << "0 " << i << ' ' << c << endl; + int ans; + cin >> ans; + }; + + int a1 = ask("1"); + int a11 = ask("11"); + int a10 = ask("10"); + + if (a1 != a11 + a10) { + answer(n, 1); + return; + } + + answer(n, 0); +} + +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 1091 (Div. 2) and CodeCraft 26/A. The Equalizer.cpp b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/A. The Equalizer.cpp new file mode 100644 index 0000000..c0aae04 --- /dev/null +++ b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/A. The Equalizer.cpp @@ -0,0 +1,121 @@ +/* Problem URL: https://codeforces.com/contest/2217/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() +{ + int n, k; + cin >> n >> k; + + vi a(n); + cin >> a; + int c = 0; + rep(i, n) { + c += a[i] & 1; + } + + if ((c & 1) || (~k & 1) || ((k & 1) && (~n & 1))) { + cout << "YES\n"; + return; + } + + cout << "NO\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 1091 (Div. 2) and CodeCraft 26/B. Flip the Bit (Easy Version).cpp b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/B. Flip the Bit (Easy Version).cpp new file mode 100644 index 0000000..100a209 --- /dev/null +++ b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/B. Flip the Bit (Easy Version).cpp @@ -0,0 +1,126 @@ +/* Problem URL: https://codeforces.com/contest/2217/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() +{ + int n, k; + cin >> n >> k; + + vi a(n); + cin >> a; + + int p; + cin >> p; + p--; + + int a1 = 0; + for (int i = p - 1; i >= 0; i--) { + a1 += a[i] != a[i + 1]; + } + + int a2 = 0; + for (int i = p + 1; i < n; i++) { + a2 += a[i] != a[i - 1]; + } + + cout << max(a1 + (a[0] != a[p]), a2 + (a[n - 1] != a[p])) << '\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 1091 (Div. 2) and CodeCraft 26/C. Grid Covering.cpp b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/C. Grid Covering.cpp new file mode 100644 index 0000000..0a4846d --- /dev/null +++ b/Codeforces Round 1091 (Div. 2) and CodeCraft 26/C. Grid Covering.cpp @@ -0,0 +1,114 @@ +/* Problem URL: https://codeforces.com/contest/2217/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() +{ + ll n, m, a, b; + cin >> n >> m >> a >> b; + + if (gcd(n, a) != 1 || gcd(m, b) != 1 || gcd(n, m) > 2) { + 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 933 (Div. 3)/F. Rudolf and Imbalance.cpp b/Codeforces Round 933 (Div. 3)/F. Rudolf and Imbalance.cpp new file mode 100644 index 0000000..7a998a7 --- /dev/null +++ b/Codeforces Round 933 (Div. 3)/F. Rudolf and Imbalance.cpp @@ -0,0 +1,193 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1941/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 n, m, k; + cin >> n >> m >> k; + + vl a(n); + vl d(m); + vl f(k); + cin >> a >> d >> f; + + map> c; + rep(i, n - 1) { + c[a[i + 1] - a[i]]++; + } + + if (c.begin()->second > 1 || c.begin()->first == 1) { + cout << c.begin()->first << '\n'; + return; + } + + sortv(d); + sortv(f); + + ll lim = c.begin()->first; + + int choice = 0; + rep(i, n - 1) { + if (a[i + 1] - a[i] == lim) { + choice = i; + break; + } + } + + auto getlesseq = [&](ll mid) { + ll ans = -1; + rep(i, m) { + auto itr = upper_bound(all(f), mid - d[i]) - f.begin(); + if (itr == 0) { + continue; + } + + rmax(ans, d[i] + f[itr - 1]); + } + + return ans; + }; + + auto getgreatereq = [&](ll mid) { + ll ans = OO; + rep(i, m) { + auto itr = lower_bound(all(f), mid - d[i]) - f.begin(); + if (itr == k) { + continue; + } + + rmin(ans, d[i] + f[itr]); + } + + return ans; + }; + + ll ch = a[choice]; + ll bt = max(ch - a[choice], a[choice + 1] - ch); + + auto getans = [&](ll m) { + if (m < a[choice] || m > a[choice + 1]) { + return; + } + ll tbt = max(m - a[choice], a[choice + 1] - m); + + if (tbt < bt) { + bt = tbt; + ch = m; + } + }; + + ll mid = (a[choice] + a[choice + 1]) >> 1; + + getans(getlesseq(mid)); + getans(getgreatereq(mid)); + + a.push_back(ch); + sortv(a); + + ll ans = 0; + rep(i, n) { + rmax(ans, a[i + 1] - a[i]); + } + + 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/Educational Codeforces Round 165 (Rated for Div. 2)/C. Minimizing the Sum.cpp b/Educational Codeforces Round 165 (Rated for Div. 2)/C. Minimizing the Sum.cpp new file mode 100644 index 0000000..d96abe7 --- /dev/null +++ b/Educational Codeforces Round 165 (Rated for Div. 2)/C. Minimizing the Sum.cpp @@ -0,0 +1,148 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1969/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, k; + cin >> n >> k; + + vl a(n); + cin >> a; + + vvl sparse(20, vl(n)); + rep(i, n) { + sparse[0][i] = a[i]; + } + + nrep(j, 1, 20) { + for (int i = 0; i + (1 << (j - 1)) < n; i++) { + sparse[j][i] = min(sparse[j - 1][i], sparse[j - 1][i + (1 << (j - 1))]); + } + } + + auto squery = [&](int l, int r) { + int log = 31 - __builtin_clz(r - l + 1); + return min(sparse[log][l], sparse[log][r - (1 << log) + 1]); + }; + + vvl memo(n, vl(k + 1, -1)); + + function dp = [&](int i, int c) { + if (i >= n) { + return 0LL; + } + + ll &ans = memo[i][c]; + if (ans != -1) { + return ans; + } + + ans = OO; + for (int j = 0; j + c <= k && i + j < n; j++) { + rmin(ans, dp(i + j + 1, c + j) + squery(i, i + j) * (j + 1)); + } + + return ans; + }; + + cout << dp(0, 0) << '\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/Hello 2024/C. Grouping Increases.cpp b/Hello 2024/C. Grouping Increases.cpp new file mode 100644 index 0000000..6caa52e --- /dev/null +++ b/Hello 2024/C. Grouping Increases.cpp @@ -0,0 +1,134 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1919/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; + vi a(n); + cin >> a; + + int x = oo; + int y = oo; + int ans = 0; + + rep(i, n) { + if (x > y) { + swap(x, y); + } + + if (a[i] <= x) { + x = a[i]; + continue; + } + + if (a[i] > y) { + x = a[i]; + ans++; + continue; + } + + y = a[i]; + } + + 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/Rayan Programming Contest 2024 - Selection (Codeforces Round 989, Div. 1 + Div. 2)/D. Darius' Wisdom.cpp b/Rayan Programming Contest 2024 - Selection (Codeforces Round 989, Div. 1 + Div. 2)/D. Darius' Wisdom.cpp new file mode 100644 index 0000000..6ed03e2 --- /dev/null +++ b/Rayan Programming Contest 2024 - Selection (Codeforces Round 989, Div. 1 + Div. 2)/D. Darius' Wisdom.cpp @@ -0,0 +1,200 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2034/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; + vi a(n); + cin >> a; + + array c = {0, 0, 0}; + set o; + rep(i, n) { + c[a[i]]++; + if (a[i] == 1) { + o.insert(i); + } + } + + V> ans; + + auto printans = [&]() { + cout << ans.size() << '\n'; + repv(i, ans) { + cout << i.first << ' ' << i.second << '\n'; + } + }; + + nrep(i, c[0], c[0] + c[1]) { + if (a[i] == 1) { + o.erase(i); + continue; + } + } + + int val = -1; + nrep(i, c[0], c[0] + c[1]) { + if (o.empty()) { + break; + } + + if (a[i] != 1) { + if (o.size() == 1) { + val = i; + break; + } + swap(a[*o.begin()], a[i]); + ans.emplace_back(*o.begin() + 1, i + 1); + o.erase(o.begin()); + } + } + + set t; + set z; + rep(i, c[0]) { + if (a[i] > 1) { + t.insert(i); + } + } + + nrep(i, c[0] + c[1], n) { + if (a[i] < 1){ + z.insert(i); + } + } + + int ch = c[0]; + if (!o.empty()) { + ch = *o.begin(); + } else { + if (t.empty() || z.empty()) { + cout << "0\n"; + return; + } + + ans.emplace_back(*t.begin() + 1, c[0] + 1); + val = c[0]; + ch = *t.begin(); + t.erase(t.begin()); + } + + int now = ch > c[0]; + while (!t.empty() || !z.empty()) { + if (now) { + ans.emplace_back(*t.begin() + 1, ch + 1); + ch = *t.begin(); + t.erase(t.begin()); + now ^= 1; + continue; + } + + ans.emplace_back(*z.begin() + 1, ch + 1); + ch = *z.begin(); + z.erase(z.begin()); + now ^= 1; + } + + ans.emplace_back(ch + 1, val + 1); + + printans(); +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!)/C. Remove the Bracket.cpp b/TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!)/C. Remove the Bracket.cpp new file mode 100644 index 0000000..3be2c3c --- /dev/null +++ b/TypeDB Forces 2023 (Div. 1 + Div. 2, Rated, Prizes!)/C. Remove the Bracket.cpp @@ -0,0 +1,139 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1787/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; + ll s; + cin >> n >> s; + vl a(n); + cin >> a; + + V> act(n); + rep(i, n) { + if (a[i] >= s * 2) { + act[i] = {s, a[i] - s}; + continue; + } + + if (a[i] >= s) { + ll diff = a[i] - s; + act[i] = {diff, a[i] - diff}; + continue; + } + + act[i] = {0, a[i]}; + } + + vvl dp(n, vl(2, OO)); + dp[1][0] = a[0] * act[1].first; + dp[1][1] = a[0] * act[1].second; + + nrep(i, 2, n - 1) { + auto [x, y] = act[i]; + auto [xb, yb] = act[i - 1]; + dp[i][0] = min(dp[i - 1][0] + (a[i - 1] - xb) * x, dp[i - 1][1] + (a[i - 1] - yb) * x); + dp[i][1] = min(dp[i - 1][0] + (a[i - 1] - xb) * y, dp[i - 1][1] + (a[i - 1] - yb) * y); + } + + cout << min(dp[n - 2][0] + (a[n - 2] - act[n - 2].first) * a[n - 1], dp[n - 2][1] + (a[n - 2] - act[n - 2].second) * a[n - 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/problemlist.md b/problemlist.md index d1e7dca..ef938e0 100644 --- a/problemlist.md +++ b/problemlist.md @@ -112,6 +112,10 @@ A little collection of interesting problems that I randomly decided to do. Interesting to think about the transitions and the states, although figuring out it's a dp problem is already a challenge by itself. +- [C. Minimizing the Sum](https://codeforces.com/problemset/problem/1969/C) + + Simple dp problem, but it's still interesting to think about it. + ## Graph @@ -128,6 +132,11 @@ A little collection of interesting problems that I randomly decided to do. A very simple problem once you finally understand it, interesting to learn about dfs and all that. +- [G1. Min-Fund Prison (Easy)](https://codeforces.com/problemset/problem/1970/G1) + + A really easy problem, at least it is once you realize that it's just a tree and the + calculation is simple. + ## Math - [E2. Rudolf and Snowflakes (hard version)](https://codeforces.com/problemset/problem/1846/E2) From f6326deecba0d326d238a2b7deabccd080e730a6 Mon Sep 17 00:00:00 2001 From: Segcolt Date: Tue, 14 Apr 2026 17:03:28 -0300 Subject: [PATCH 2/3] A bunch more problems --- .../L. Bridge Renovation.cpp | 143 ++++++++++++ .../C. Customer Service.cpp | 131 +++++++++++ .../D. Counting Points.cpp | 142 ++++++++++++ .../A. Ntarsis' Set.cpp | 134 ++++++++++++ .../B. Imbalanced Arrays.cpp | 149 +++++++++++++ .../C. Watering an Array.cpp | 134 ++++++++++++ .../D. Array Repetition.cpp | 154 +++++++++++++ .../C. LR-remainders.cpp | 140 ++++++++++++ ...Adjust The Presentation (Hard Version).cpp | 207 ++++++++++++++++++ .../C. Binary String Copying.cpp | 134 ++++++++++++ .../D. Slimes.cpp | 189 ++++++++++++++++ TODO.md | 5 + 12 files changed, 1662 insertions(+) create mode 100644 2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/L. Bridge Renovation.cpp create mode 100644 Codeforces Round 1002 (Div. 2)/C. Customer Service.cpp create mode 100644 Codeforces Round 1009 (Div. 3)/D. Counting Points.cpp create mode 100644 Codeforces Round 887 (Div. 1)/A. Ntarsis' Set.cpp create mode 100644 Codeforces Round 887 (Div. 1)/B. Imbalanced Arrays.cpp create mode 100644 Codeforces Round 917 (Div. 2)/C. Watering an Array.cpp create mode 100644 Codeforces Round 919 (Div. 2)/D. Array Repetition.cpp create mode 100644 Codeforces Round 927 (Div. 3)/C. LR-remainders.cpp create mode 100644 Codeforces Round 977 (Div. 2, based on COMPFEST 16 - Final Round)/C2. Adjust The Presentation (Hard Version).cpp create mode 100644 Educational Codeforces Round 152 (Rated for Div. 2)/C. Binary String Copying.cpp create mode 100644 Educational Codeforces Round 162 (Rated for Div. 2)/D. Slimes.cpp diff --git a/2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/L. Bridge Renovation.cpp b/2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/L. Bridge Renovation.cpp new file mode 100644 index 0000000..28348bb --- /dev/null +++ b/2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/L. Bridge Renovation.cpp @@ -0,0 +1,143 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2038/L */ + +#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 0 + +void solve() +{ + int n; + cin >> n; + + vvl memo(n + 1, vl(n + 1, -1)); + + function dp = [&](int i, int j) { + if (i == 0 && j == 0) { + return 0LL; + } + + ll &ans = memo[i][j]; + if (ans != -1) { + return ans; + } + + ans = OO; + rep(k, 4) { + rep(l, 4) { + if ((k == 0 && l == 0) || (60 - 18 * k - 21 * l < 0)) { + continue; + } + + if (k > i || l > j) { + continue; + } + + rmin(ans, dp(i - k, j - l) + 1); + } + } + + return ans; + }; + + if (n & 1) { + cout << min(dp(n - 1, n), dp(n, n - 1)) + n / 2 + 1 << '\n'; + return; + } + + cout << dp(n, n) + n / 2 << '\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 1002 (Div. 2)/C. Customer Service.cpp b/Codeforces Round 1002 (Div. 2)/C. Customer Service.cpp new file mode 100644 index 0000000..a581a3a --- /dev/null +++ b/Codeforces Round 1002 (Div. 2)/C. Customer Service.cpp @@ -0,0 +1,131 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2059/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; + + vvl a(n, vl(n)); + cin >> a; + + vi c(n); + rep(i, n) { + for (int j = n - 1; j >= 0 && a[i][j] == 1; j--) { + c[i]++; + } + } + + sortv(c); + int ans = 0; + int cur = 0; + + rep(i, n) { + if (c[i] >= cur) { + ans++; + cur++; + continue; + } + } + + 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 1009 (Div. 3)/D. Counting Points.cpp b/Codeforces Round 1009 (Div. 3)/D. Counting Points.cpp new file mode 100644 index 0000000..5ba7947 --- /dev/null +++ b/Codeforces Round 1009 (Div. 3)/D. Counting Points.cpp @@ -0,0 +1,142 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2074/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, m; + cin >> n >> m; + + vl a(n); + cin >> a; + vl r(n); + cin >> r; + + map c; + rep(i, n) { + ll x = a[i] - r[i]; + ll y = 0; + auto valid = [&](ll x, ll y) { + ll xi = (x - a[i]); + return xi * xi + y * y <= r[i] * r[i]; + }; + + while (x <= a[i] + r[i]) { + while (!valid(x, y)) { + y--; + } + + while (valid(x, y + 1)) { + y++; + } + + rmax(c[x], y + 1); + x++; + } + } + + ll ans = 0; + repv(i, c) { + ans += i.second * 2 - 1; + } + + 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 887 (Div. 1)/A. Ntarsis' Set.cpp b/Codeforces Round 887 (Div. 1)/A. Ntarsis' Set.cpp new file mode 100644 index 0000000..c4ff589 --- /dev/null +++ b/Codeforces Round 887 (Div. 1)/A. Ntarsis' Set.cpp @@ -0,0 +1,134 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1852/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() +{ + int n, k; + cin >> n >> k; + vl a(n); + cin >> a; + + ll low = 1; + ll high = 1e18; + while (low < high) { + ll mid = (low + high) >> 1; + + auto check = [&]() { + ll cur = mid; + rep(i, k) { + int it = upper_bound(all(a), cur) - a.begin(); + cur -= it; + } + + return cur; + }; + + if (check() > 0) { + high = mid; + continue; + } + + low = mid + 1; + } + + cout << low << '\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 887 (Div. 1)/B. Imbalanced Arrays.cpp b/Codeforces Round 887 (Div. 1)/B. Imbalanced Arrays.cpp new file mode 100644 index 0000000..7521ef2 --- /dev/null +++ b/Codeforces Round 887 (Div. 1)/B. Imbalanced Arrays.cpp @@ -0,0 +1,149 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1852/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() +{ + int n; + cin >> n; + vi a(n); + cin >> a; + + V> v; + rep(i, n) { + v.emplace_back(a[i], i); + } + + sortv(v); + + int sz = n; + int l = 0; + int r = n - 1; + int d = 0; + while (sz--) { + int al = v[l].first - d; + int ar = v[r].first - d; + + if (al == 0 && ar == sz + 1) { + cout << "NO\n"; + return; + } + + if (al == 0) { + a[v[l].second] = -sz - 1; + l++; + continue; + } + + if (ar == sz + 1) { + a[v[r].second] = sz + 1; + r--; + d++; + continue; + } + + cout << "NO\n"; + return; + } + + cout << "YES\n"; + cout << a; +} + +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 917 (Div. 2)/C. Watering an Array.cpp b/Codeforces Round 917 (Div. 2)/C. Watering an Array.cpp new file mode 100644 index 0000000..caa9a40 --- /dev/null +++ b/Codeforces Round 917 (Div. 2)/C. Watering an Array.cpp @@ -0,0 +1,134 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1917/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() +{ + ll n, k, d; + cin >> n >> k >> d; + + vi a(n); + cin >> a; + vi v(k); + cin >> v; + + ll ans = 0; + rep(i, 2 * n + 1) { + d--; + ll calc = 0; + rep(j, n) { + if (a[j] == j + 1) { + calc++; + } + } + rmax(ans, calc + d / 2); + + if (d == 0) { + break; + } + + rep(j, v[i % k]) { + 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 919 (Div. 2)/D. Array Repetition.cpp b/Codeforces Round 919 (Div. 2)/D. Array Repetition.cpp new file mode 100644 index 0000000..11984d1 --- /dev/null +++ b/Codeforces Round 919 (Div. 2)/D. Array Repetition.cpp @@ -0,0 +1,154 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1920/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, q; + cin >> n >> q; + + struct node { + __int128 r; + __int128 n; + vl last; + }; + + V act; + act.push_back({0, 0, vl()}); + + bool stop = false; + + while (n--) { + int op; + ll x; + cin >> op >> x; + if (stop) { + continue; + } + + if (op == 1) { + act.back().n++; + act.back().last.push_back(x); + continue; + } + + auto &cur = act.back(); + act.push_back({cur.n * (x + 1), cur.n * (x + 1), vl()}); + if (act.back().n > 1e18) { + stop = true; + } + } + + while (q--) { + ll k; + cin >> k; + k--; + + int i = act.size() - 1; + while (act[i].r > k) { + i--; + k %= act[i].n; + } + + cout << act[i].last[k - act[i].r] << ' '; + } + 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 927 (Div. 3)/C. LR-remainders.cpp b/Codeforces Round 927 (Div. 3)/C. LR-remainders.cpp new file mode 100644 index 0000000..c5dd6b7 --- /dev/null +++ b/Codeforces Round 927 (Div. 3)/C. LR-remainders.cpp @@ -0,0 +1,140 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1932/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, m; + cin >> n >> m; + vi a(n); + cin >> a; + string s; + cin >> s; + + int l = 0; + int r = n - 1; + repv(i, s) { + if (i == 'L') { + l++; + continue; + } + + r--; + } + + reverse(all(s)); + ll ans = 1; + vl act; + + repv(i, s) { + if (i == 'L') { + l--; + ans *= a[l]; + } else { + r++; + ans *= a[r]; + } + ans %= m; + act.push_back(ans); + } + reverse(all(act)); + cout << act; +} + +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 977 (Div. 2, based on COMPFEST 16 - Final Round)/C2. Adjust The Presentation (Hard Version).cpp b/Codeforces Round 977 (Div. 2, based on COMPFEST 16 - Final Round)/C2. Adjust The Presentation (Hard Version).cpp new file mode 100644 index 0000000..f1bc31e --- /dev/null +++ b/Codeforces Round 977 (Div. 2, based on COMPFEST 16 - Final Round)/C2. Adjust The Presentation (Hard Version).cpp @@ -0,0 +1,207 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2021/C2 */ + +#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, q; + cin >> n >> m >> q; + + vi a(n); + cin >> a; + + vi var(n); + V> ap(n); + rep(i, n) { + var[a[i] - 1] = i; + ap[i].insert(oo); + } + + vi b(m); + rep(i, m) { + cin >> b[i]; + ap[var[b[i] - 1]].insert(i); + } + + int sz = n; + while (__builtin_popcount(sz) != 1) { + sz++; + } + + V>> seg(sz * 2); + vl sum(sz * 2); + nrep(i, sz, sz * 2) { + seg[i].insert({oo, i - sz}); + } + + for (int i = sz - 1; i > 0; i--) { + repv(j, seg[i * 2]) { + seg[i].insert(j); + } + repv(j, seg[i * 2 + 1]) { + seg[i].insert(j); + } + } + + auto update = [&](int i, int v) { + int ind = i; + i += sz; + auto bf = *seg[i].begin(); + seg[i].clear(); + seg[i].insert({v, i - sz}); + int now = i & 1; + int dd = 0; + + for (i >>= 1; i > 0; i >>= 1) { + seg[i].erase(bf); + seg[i].insert({v, ind}); + sum[i] += dd; + + if (now) { + int s = seg[i * 2].size() - seg[i * 2].order_of_key({v, oo}); + int s2 = seg[i * 2].size() - seg[i * 2].order_of_key({bf.first, oo}); + sum[i] -= s2; + sum[i] += s; + dd -= s2; + dd += s; + } else { + int s = seg[i * 2 + 1].order_of_key({v, -1}); + int s2 = seg[i * 2 + 1].order_of_key({bf.first, -1}); + sum[i] -= s2; + sum[i] += s; + dd -= s2; + dd += s; + } + + now = i & 1; + } + }; + + rep(i, n) { + update(i, *ap[i].begin()); + } + + auto check = [&]() { + string ans[] = { + "TIDAK", + "YA" + }; + cout << ans[sum[1] == 0] << '\n'; + }; + + check(); + while (q--) { + int i, j; + cin >> i >> j; + i--; + + int bf = b[i]; + b[i] = j; + int actbf = var[bf - 1]; + int actb = var[b[i] - 1]; + + ap[actbf].erase(i); + ap[actb].insert(i); + update(actbf, *ap[actbf].begin()); + update(actb, *ap[actb].begin()); + check(); + } +} + +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 152 (Rated for Div. 2)/C. Binary String Copying.cpp b/Educational Codeforces Round 152 (Rated for Div. 2)/C. Binary String Copying.cpp new file mode 100644 index 0000000..159ad9d --- /dev/null +++ b/Educational Codeforces Round 152 (Rated for Div. 2)/C. Binary String Copying.cpp @@ -0,0 +1,134 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1849/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, m; + cin >> n >> m; + string a; + cin >> a; + + vi lg(n); + vi rg(n); + + lg[0] -= a[0] != '0'; + rg[n - 1] = n - (a[n - 1] == '1'); + nrep(i, 1, n) { + lg[i] = max(lg[i - 1], i - oo * (a[i] != '0')); + rg[n - i - 1] = min(rg[n - i], n - i - 1 + oo * (a[n - i - 1] != '1')); + } + + set> ans; + while (m--) { + int l, r; + cin >> l >> r; + l--, r--; + + if (rg[l] > lg[r]) { + ans.emplace(-1, -1); + continue; + } + + ans.emplace(rg[l], lg[r]); + } + + cout << ans.size() << '\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 162 (Rated for Div. 2)/D. Slimes.cpp b/Educational Codeforces Round 162 (Rated for Div. 2)/D. Slimes.cpp new file mode 100644 index 0000000..c3b1607 --- /dev/null +++ b/Educational Codeforces Round 162 (Rated for Div. 2)/D. Slimes.cpp @@ -0,0 +1,189 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1923/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; + + vl pref(n + 1); + nrep(i, 1, n + 1) { + pref[i] = pref[i - 1] + a[i - 1]; + } + + vvi sparse(20, vi(n - 1)); + rep(i, n - 1) { + sparse[0][i] = a[i] != a[i + 1]; + } + + nrep(j, 1, 20) { + for (int i = 0; i + (1 << (j - 1)) < n - 1; i++) { + sparse[j][i] = sparse[j - 1][i] | sparse[j - 1][i + (1 << (j - 1))]; + } + } + + auto query = [&](int l, int r) { + int log = 31 - __builtin_clz(r - l + 1); + return sparse[log][l] | sparse[log][r - (1 << log) + 1]; + }; + + rep(i, n) { + if (i > 0 && a[i - 1] > a[i]) { + cout << "1 "; + continue; + } + + if (i < n - 1 && a[i + 1] > a[i]) { + cout << "1 "; + continue; + } + + auto calcbf = [&]() { + int low = 0; + int high = i - 2; + int ans = oo; + while (low <= high) { + int mid = (low + high) >> 1; + + if (!query(mid, i - 2) || pref[i] - pref[mid] <= a[i]) { + high = mid - 1; + continue; + } + + low = mid + 1; + ans = i - mid; + } + + return ans; + }; + + auto calcnx = [&]() { + int low = i + 2; + int high = n - 1; + int ans = oo; + while (low <= high) { + int mid = (low + high) >> 1; + + if (!query(i + 1, mid - 1) || pref[mid + 1] - pref[i + 1] <= a[i]) { + low = mid + 1; + continue; + } + + high = mid - 1; + ans = mid - i; + } + + return ans; + }; + + int ans = min(calcbf(), calcnx()); + if (ans == oo) { + cout << "-1 "; + continue; + } + + cout << ans << ' '; + } + 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/TODO.md b/TODO.md index 5193f8a..32f5727 100644 --- a/TODO.md +++ b/TODO.md @@ -146,6 +146,11 @@ Official divs from codeforces I honestly have no idea how to solve this, the editorial didn't help much, I'll get back at it after learning NTT or something. + + - [ ] [C2. Adjust The Presentation (Hard Version)](https://codeforces.com/problemset/problem/2021/C2) + + I already have the idea figured out, but my solution ended up getting TLE, I'll have to come + with something better. - Div 3 From f34355b975270d5d8248f373cadedf35cdcffcb4 Mon Sep 17 00:00:00 2001 From: Segcolt Date: Tue, 14 Apr 2026 17:08:13 -0300 Subject: [PATCH 3/3] Some problems for the list --- problemlist.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/problemlist.md b/problemlist.md index ef938e0..54dd92f 100644 --- a/problemlist.md +++ b/problemlist.md @@ -17,6 +17,11 @@ A little collection of interesting problems that I randomly decided to do. Another incredibly annoying problem, beware... +- [D. Counting Points]](https://codeforces.com/problemset/problem/2074/D) + + I remember that I couldn't solve it before... Now it's painfully easy to do, but the + idea might be interesting to show in a class or something. + ## Data structures - [D. Recommendations](https://codeforces.com/contest/2042/problem/D) @@ -41,6 +46,11 @@ A little collection of interesting problems that I randomly decided to do. Can be solved in two ways, but the sparse table one is interesting, although the other way seems more versatile. +- [A. Ntarsis' Set](https://codeforces.com/problemset/problem/1852/A) + + REALLY good binary search problem, amazing to do and think about, the binary search isn't + obvious at all. + ## Reroot - [D. Tree XOR](https://codeforces.com/problemset/problem/1882/D)