From ab40694aa7d2e4733d0391180d61e9908034844f Mon Sep 17 00:00:00 2001 From: Segcolt Date: Fri, 3 Apr 2026 14:51:26 -0300 Subject: [PATCH] More problems --- .../J. Polygons Intersection.cpp | 199 +++++++++++++++++ .../E. Easy Assembly.cpp | 139 ++++++++++++ .../F. Cluster Computing System.cpp | 125 +++++++++++ .../A. Odd One Out.cpp | 106 +++++++++ .../B. Are You Smiling?.cpp | 106 +++++++++ April Fools Day Contest 2026/C. And?.cpp | 110 +++++++++ .../D. Neural Feud.cpp | 119 ++++++++++ .../E. Shortest Paths.cpp | 132 +++++++++++ April Fools Day Contest 2026/G. Anomaly.cpp | 109 +++++++++ .../H. Double Vision.cpp | 106 +++++++++ .../J. Special Problem.cpp | 106 +++++++++ ...t was Built by Love, Broken by Destiny.cpp | 209 ++++++++++++++++++ .../E1. Submedians (Easy Version).cpp | 172 ++++++++++++++ .../D. Beautiful Permutation.cpp | 141 ++++++++++++ .../E. Exquisite Array.cpp | 178 +++++++++++++++ ...2. A Simple GCD Problem (Hard Version).cpp | 177 +++++++-------- .../D. Row Major.cpp | 140 ++++++++++++ .../D. Andrey and Escape from Capygrad.cpp | 199 +++++++++++++++++ .../E. Cells Arrangement.cpp | 114 ++++++++++ TODO.md | 7 +- .../D. Arcology On Permafrost.cpp | 117 ++++++++++ problemlist.md | 1 - 22 files changed, 2716 insertions(+), 96 deletions(-) create mode 100644 2015 HIAST Collegiate Programming Contest/J. Polygons Intersection.cpp create mode 100644 2022-2023 ICPC, NERC, Northern Eurasia Onsite (Unrated, Online Mirror, ICPC Rules, Teams Preferred)/E. Easy Assembly.cpp create mode 100644 2025 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/F. Cluster Computing System.cpp create mode 100644 April Fools Day Contest 2026/A. Odd One Out.cpp create mode 100644 April Fools Day Contest 2026/B. Are You Smiling?.cpp create mode 100644 April Fools Day Contest 2026/C. And?.cpp create mode 100644 April Fools Day Contest 2026/D. Neural Feud.cpp create mode 100644 April Fools Day Contest 2026/E. Shortest Paths.cpp create mode 100644 April Fools Day Contest 2026/G. Anomaly.cpp create mode 100644 April Fools Day Contest 2026/H. Double Vision.cpp create mode 100644 April Fools Day Contest 2026/J. Special Problem.cpp create mode 100644 Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2)/D. Root was Built by Love, Broken by Destiny.cpp create mode 100644 Codeforces Round 1039 (Div. 2)/E1. Submedians (Easy Version).cpp create mode 100644 Codeforces Round 1059 (Div. 3)/D. Beautiful Permutation.cpp create mode 100644 Codeforces Round 1072 (Div. 3)/E. Exquisite Array.cpp create mode 100644 Codeforces Round 884 (Div. 1 + Div. 2)/D. Row Major.cpp create mode 100644 Codeforces Round 892 (Div. 2)/D. Andrey and Escape from Capygrad.cpp create mode 100644 Codeforces Round 943 (Div. 3)/E. Cells Arrangement.cpp create mode 100644 Teza Round 1 (Codeforces Round 1015, Div. 1 + Div. 2)/D. Arcology On Permafrost.cpp diff --git a/2015 HIAST Collegiate Programming Contest/J. Polygons Intersection.cpp b/2015 HIAST Collegiate Programming Contest/J. Polygons Intersection.cpp new file mode 100644 index 0000000..1b910f5 --- /dev/null +++ b/2015 HIAST Collegiate Programming Contest/J. Polygons Intersection.cpp @@ -0,0 +1,199 @@ +/* Problem URL: https://codeforces.com/gym/100952/problem/J */ + +#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; + +using ld = long double; + +struct pt { + ld x, y; + + pt() = default; + pt(ld x, ld y): x(x), y(y) {} + + friend istream &operator >> (istream &is, pt &a) { + is >> a.x >> a.y; + return is; + } + + ld operator ^ (pt b) { + return x * b.y - y * b.x; + } + + pt operator - (pt b) { + return pt(x - b.x, y - b.y); + } +}; + +#define eq(x, y) (abs(x - y) < EPS) + +ll sarea2(pt a, pt b, pt c) +{ + return ((b - a) ^ (c - b)); +} + +int ccw(pt a, pt b, pt c) +{ + ld r = sarea2(a, b, c); + return (r > 0) - (r < 0); +} + +struct line { + pt a; + pt b; + + line() = default; + line(pt a, pt b): a(a), b(b) {} +}; + +bool lineinter(line a, line b) { + return ccw(a.a, a.b, b.a) != ccw(a.a, a.b, b.b) && ccw(b.a, b.b, a.a) != ccw(b.a, b.b, a.b); +} + +pt linept(line a, line b) { + ld l1[] = {a.b.y - a.a.y, a.a.x - a.b.x, a.a ^ a.b}; + ld l2[] = {b.b.y - b.a.y, b.a.x - b.b.x, b.a ^ b.b}; + ld det = l1[0] * l2[1] - l1[1] * l2[0]; + + return pt((l2[1] * l1[2] - l1[1] * l2[2]) / det, (l2[0] * l1[2] - l1[0] * l2[2]) / det); +} + +void pre() +{ + +} + +#define TEST 1 + +void solve() +{ + int n, m; + cin >> n >> m; + + V a(n); + V b(m); + cin >> a >> b; + + V act[2]; + int now = 0; + + rep(i, n) { + pt p1 = a[i]; + pt p2 = a[(i + 1) % n]; + + auto inter = [&](line a) { + rep(j, m) { + pt p3 = b[j]; + pt p4 = b[(j + 1) % m]; + + if (!lineinter(a, line(p3, p4))) { + continue; + } + + act[0].emplace_back(linept(a, line(p3, p4))); + act[1].emplace_back(linept(a, line(p3, p4))); + return true; + } + + return false; + }; + + if (inter(line(p1, p2))) { + now ^= 1; + continue; + } + + act[now].emplace_back(p1); + } + + +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/2022-2023 ICPC, NERC, Northern Eurasia Onsite (Unrated, Online Mirror, ICPC Rules, Teams Preferred)/E. Easy Assembly.cpp b/2022-2023 ICPC, NERC, Northern Eurasia Onsite (Unrated, Online Mirror, ICPC Rules, Teams Preferred)/E. Easy Assembly.cpp new file mode 100644 index 0000000..4b4e5eb --- /dev/null +++ b/2022-2023 ICPC, NERC, Northern Eurasia Onsite (Unrated, Online Mirror, ICPC Rules, Teams Preferred)/E. Easy Assembly.cpp @@ -0,0 +1,139 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1773/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 0 + +void solve() +{ + int n; + cin >> n; + + vvi a(n); + vi var; + + rep(i, n) { + int s; + cin >> s; + a[i].resize(s); + repv(i, a[i]) { + cin >> i; + var.push_back(i); + } + } + + sortv(var); + + rep(i, n) { + repv(i, a[i]) { + i = lower_bound(all(var), i) - var.begin(); + } + } + + int ans = n - 1; + rep(i, n) { + nrep(j, 1, a[i].size()) { + if (a[i][j] != a[i][j - 1] + 1) { + ans++; + } + } + } + + cout << ans - (n - 1) << ' ' << 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/2025 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/F. Cluster Computing System.cpp b/2025 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/F. Cluster Computing System.cpp new file mode 100644 index 0000000..05b3265 --- /dev/null +++ b/2025 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams)/F. Cluster Computing System.cpp @@ -0,0 +1,125 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2172/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 0 + +void solve() +{ + int n; + cin >> n; + vl p(n); + cin >> p; + + vl suf(n); + suf[n - 1] = p[n - 1]; + for (int i = n - 2; i >= 0; i--) { + suf[i] = gcd(suf[i + 1], p[i]); + } + + ll ans = suf[0]; + ll gc = p[0]; + + nrep(i, 1, n - 1) { + gc = gcd(gc, p[i]); + ans += min(gc, suf[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/April Fools Day Contest 2026/A. Odd One Out.cpp b/April Fools Day Contest 2026/A. Odd One Out.cpp new file mode 100644 index 0000000..ac6b348 --- /dev/null +++ b/April Fools Day Contest 2026/A. Odd One Out.cpp @@ -0,0 +1,106 @@ +/* Problem URL: https://codeforces.com/contest/2214/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 0 + +void solve() +{ + cout << "C2\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/April Fools Day Contest 2026/B. Are You Smiling?.cpp b/April Fools Day Contest 2026/B. Are You Smiling?.cpp new file mode 100644 index 0000000..f34385f --- /dev/null +++ b/April Fools Day Contest 2026/B. Are You Smiling?.cpp @@ -0,0 +1,106 @@ +/* Problem URL: https://codeforces.com/contest/2214/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 0 + +void solve() +{ + cout << "1F600\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/April Fools Day Contest 2026/C. And?.cpp b/April Fools Day Contest 2026/C. And?.cpp new file mode 100644 index 0000000..4960587 --- /dev/null +++ b/April Fools Day Contest 2026/C. And?.cpp @@ -0,0 +1,110 @@ +/* Problem URL: https://codeforces.com/contest/2214/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 a[3]; + cin >> a[0] >> a[1] >> a[2]; + sort(a, a + 3); + + cout << ((a[0] ^ a[1] ^ a[2]) - a[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/April Fools Day Contest 2026/D. Neural Feud.cpp b/April Fools Day Contest 2026/D. Neural Feud.cpp new file mode 100644 index 0000000..6de228a --- /dev/null +++ b/April Fools Day Contest 2026/D. Neural Feud.cpp @@ -0,0 +1,119 @@ +/* Problem URL: https://codeforces.com/contest/2214/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; + + +void pre() +{ + +} + +#define TEST 0 + +void solve() +{ + int n; + cin >> n; + + string ans[] = { + "walk", + "no", + "no", + "no", + "yes", + "yes", + "backwards", + "7" + }; + cout << ans[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/April Fools Day Contest 2026/E. Shortest Paths.cpp b/April Fools Day Contest 2026/E. Shortest Paths.cpp new file mode 100644 index 0000000..9e3db32 --- /dev/null +++ b/April Fools Day Contest 2026/E. Shortest Paths.cpp @@ -0,0 +1,132 @@ +/* Problem URL: https://codeforces.com/contest/2214/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 0 + +void solve() +{ + int n, m; + cin >> n >> m; + + vvl dis(n, vl(n, OO)); + rep(i, n) { + dis[i][i] = 0; + } + + while (m--) { + int a, b, c; + cin >> a >> b >> c; + a--, b--; + rmin(dis[a][b], (ll)c); + rmin(dis[b][a], (ll)c); + } + + rep(i, n) { + rep(k, n) { + rep(j, n) { + rmin(dis[i][j], dis[i][k] + dis[k][j]); + } + } + } + + nrep(i, 1, n) { + cout << (dis[0][i] == OO ? -1 : dis[0][i]) << '\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/April Fools Day Contest 2026/G. Anomaly.cpp b/April Fools Day Contest 2026/G. Anomaly.cpp new file mode 100644 index 0000000..204fd47 --- /dev/null +++ b/April Fools Day Contest 2026/G. Anomaly.cpp @@ -0,0 +1,109 @@ +/* Problem URL: https://codeforces.com/contest/2214/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() +{ + string ans = "_i_c_______"; + int n; + cin >> n; + cout << ans[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/April Fools Day Contest 2026/H. Double Vision.cpp b/April Fools Day Contest 2026/H. Double Vision.cpp new file mode 100644 index 0000000..a62ee4f --- /dev/null +++ b/April Fools Day Contest 2026/H. Double Vision.cpp @@ -0,0 +1,106 @@ +/* Problem URL: https://codeforces.com/contest/2214/problem/H */ + +#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() +{ + cout << "YU5zV2VS\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/April Fools Day Contest 2026/J. Special Problem.cpp b/April Fools Day Contest 2026/J. Special Problem.cpp new file mode 100644 index 0000000..7f414e3 --- /dev/null +++ b/April Fools Day Contest 2026/J. Special Problem.cpp @@ -0,0 +1,106 @@ +/* Problem URL: https://codeforces.com/contest/2214/problem/J */ + +#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() +{ + cout << "Yes, I can attest to my status as a thoroughly validated, carbon-based biological entity.\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/Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2)/D. Root was Built by Love, Broken by Destiny.cpp b/Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2)/D. Root was Built by Love, Broken by Destiny.cpp new file mode 100644 index 0000000..a522e11 --- /dev/null +++ b/Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2)/D. Root was Built by Love, Broken by Destiny.cpp @@ -0,0 +1,209 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2127/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; + +const ll mod = 1e9 + 7; +constexpr int MAXN = 2e5 + 10; +ll fact[MAXN]; + +void pre() +{ + fact[0] = 1; + nrep(i, 1, MAXN) { + fact[i] = fact[i - 1] * i % mod; + } +} + +#define TEST 1 + +void solve() +{ + int n, m; + cin >> n >> m; + if (m != n - 1) { + while (m--) { + int a, b; + cin >> a >> b; + } + cout << "0\n"; + return; + } + + vvi graph(n); + while (m--) { + int a, b; + cin >> a >> b; + a--, b--; + graph[a].push_back(b); + graph[b].push_back(a); + } + + vi g(n, -1); + vi gr(n); + vi cr; + + int c = 0; + function dfs = [&](int i) { + gr[i] = c; + cr[c]++; + repv(j, graph[i]){ + if (g[j] == -1) { + g[j] = g[i] ^ 1; + if (!dfs(j)) { + return false; + } + continue; + } + + if (g[j] == g[i]) { + return false; + } + } + + return true; + }; + + auto fpow = [&](ll a, ll p) { + ll ans = 1; + rep(i, 61) { + if ((p >> i) & 1) { + (ans *= a) %= mod; + } + (a *= a) %= mod; + } + return ans; + }; + + int c2 = 0; + + rep(i, n) { + if (g[i] != -1) { + continue; + } + + g[i] = 0; + cr.push_back(0); + if (!dfs(i)) { + cout << "0\n"; + return; + } + c2 += cr[c] > 2; + c++; + } + + ll ans = fpow(2, c + c2); + + rep(i, n) { + if (graph[i].size() <= 2) { + continue; + } + + int c1 = 0; + repv(j, graph[i]) { + c1 += graph[j].size() >= 2; + } + + if (c1 > 2) { + cout << "0\n"; + return; + } + + if (c1 == 0) { + (ans *= fpow(2, mod - 2)) %= mod; + } + + (ans *= fact[graph[i].size() - c1]) %= 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 1039 (Div. 2)/E1. Submedians (Easy Version).cpp b/Codeforces Round 1039 (Div. 2)/E1. Submedians (Easy Version).cpp new file mode 100644 index 0000000..0c8539c --- /dev/null +++ b/Codeforces Round 1039 (Div. 2)/E1. Submedians (Easy Version).cpp @@ -0,0 +1,172 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2128/E1 */ + +#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() +{ + ordered_set> ord; + + int n, k; + cin >> n >> k; + vi p(n); + cin >> p; + + int ans = -1; + int al = -1; + int ar = -1; + auto getans = [&](int l, int r, int med) { + if (med > ans) { + ans = med; + al = l; + ar = r; + } + }; + + int low = 1; + int high = n; + while (low <= high) { + int mid = (low + high) >> 1; + + vi big(n); + rep(i, n) { + big[i] = (p[i] >= mid) - (p[i] < mid); + } + + vl sum(n + 1); + + nrep(i, 1, k + 1) { + sum[i] = sum[i - 1] + big[i - 1]; + } + + int tl = 1; + int ttl = 1; + int tr = k; + + ll cur = sum[k]; + ll act = cur; + ll mi = 0; + nrep(i, k + 1, n + 1) { + cur += big[i - 1]; + if (mi > sum[i - k]) { + mi = sum[i - k]; + tl = i - k + 1; + } + if (act < cur - mi) { + act = cur - mi; + tr = i; + ttl = tl; + } + sum[i] = cur; + } + + if (act >= 0) { + ans = mid; + al = ttl; + ar = tr; + low = mid + 1; + continue; + } + + high = mid - 1; + } + + cout << ans << ' ' << al << ' ' << ar << '\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 1059 (Div. 3)/D. Beautiful Permutation.cpp b/Codeforces Round 1059 (Div. 3)/D. Beautiful Permutation.cpp new file mode 100644 index 0000000..a53716a --- /dev/null +++ b/Codeforces Round 1059 (Div. 3)/D. Beautiful Permutation.cpp @@ -0,0 +1,141 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2162/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; + + auto ask = [&](int t, int l, int r) { + cout << t << ' ' << l << ' ' << r << endl; + int ans; + cin >> ans; + return ans; + }; + + auto answer = [&](int l, int r) { + cout << "! " << l << ' ' << r << endl; + }; + + int a1 = ask(1, 1, n); + int a2 = ask(2, 1, n); + int sz = a2 - a1; + + int low = 1; + int high = n; + + while (low < high) { + int mid = (low + high) >> 1; + + a1 = ask(1, 1, mid); + a2 = ask(2, 1, mid); + int diff = a2 - a1; + if (diff) { + high = mid; + continue; + } + + low = mid + 1; + } + + answer(low, low + sz - 1); +} + +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 1072 (Div. 3)/E. Exquisite Array.cpp b/Codeforces Round 1072 (Div. 3)/E. Exquisite Array.cpp new file mode 100644 index 0000000..ab5e8e8 --- /dev/null +++ b/Codeforces Round 1072 (Div. 3)/E. Exquisite Array.cpp @@ -0,0 +1,178 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2184/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; + vi p(n); + cin >> p; + + vi diff(n - 1); + nrep(i, 1, n) { + diff[i - 1] = abs(p[i] - p[i - 1]); + } + + vvi sparse(20, vi(n - 1)); + rep(i, n - 1) { + sparse[0][i] = diff[i]; + } + + nrep(j, 1, 20) { + for (int i = 0; i + (1 << (j - 1)) < n - 1; i++) { + sparse[j][i] = min(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 min(sparse[log][l], sparse[log][r - (1 << log) + 1]); + }; + + vl ans(n + 1); + vi lim(n + 1, -1); + + rep(i, n - 1) { + int low = i; + int high = n - 2; + int r = i; + while (low <= high) { + int mid = (low + high) >> 1; + + int q = query(i, mid); + if (q == diff[i]) { + r = mid; + low = mid + 1; + continue; + } + + high = mid - 1; + } + + low = lim[diff[i]] + 1; + high = i; + int l = i; + while (low <= high) { + int mid = (low + high) >> 1; + + int q = query(mid, i); + if (q == diff[i]) { + l = mid; + high = mid - 1; + continue; + } + + low = mid + 1; + } + + ll act = (ll)(i - l + 1) * (ll)(r - i + 1); + ans[0] += act; + ans[diff[i] + 1] -= act; + lim[diff[i]] = i; + } + + nrep(i, 1, n) { + ans[i] += ans[i - 1]; + cout << ans[i] << ' '; + } + 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 1089 (Div. 2)/C2. A Simple GCD Problem (Hard Version).cpp b/Codeforces Round 1089 (Div. 2)/C2. A Simple GCD Problem (Hard Version).cpp index 5a81c56..1658045 100644 --- a/Codeforces Round 1089 (Div. 2)/C2. A Simple GCD Problem (Hard Version).cpp +++ b/Codeforces Round 1089 (Div. 2)/C2. A Simple GCD Problem (Hard Version).cpp @@ -78,37 +78,12 @@ auto operator>>(istream &is, vector> &vec)->istream& { const int oo = INT32_MAX >> 1; const ll OO = INT64_MAX >> 1; -constexpr int MAXN = 5e4 + 10; -int di[MAXN]; -vi divs[MAXN]; -vi primes; +ll p[] = {1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113}; +int ps = sizeof(p) / sizeof(ll); void pre() { - // fill(di, di + MAXN, 1); - // iota(di, di + MAXN, 0); - // primes.push_back(1); - // nrep(i, 2, MAXN) { - // if (di[i] != i) { - // continue; - // } - // primes.push_back(i); - // - // for (int j = i; j < MAXN; j += i) { - // di[j] = i; - // } - // } - // nrep(i, 2, MAXN) { - // int cur = i; - // while (cur > 1) { - // int now = di[i]; - // divs[i].push_back(now); - // while (di[i] == now) { - // i /= now; - // } - // } - // } } #define TEST 1 @@ -117,87 +92,101 @@ void solve() { int n; cin >> n; + vl a(n); vl b(n); + cin >> a >> b; - // vl act(n); - // act[0] = gcd(a[0], a[1]); - // act[n - 1] = gcd(a[n - 1], a[n - 2]); - // - // nrep(i, 1, n - 1) { - // ll g1 = gcd(a[i], a[i + 1]); - // ll g2 = gcd(a[i], a[i - 1]); - // - // act[i] = lcm(g1, g2); - // } - // - priority_queue> pq; - rep(i, n) { - pq.emplace(b[i], i); + vl act(n); + V rem(n); + act[0] = gcd(a[0], a[1]); + if (act[0] > b[0]) { + act[0] = a[0]; } - int act = 0; + if (act[0] != a[0]) { + rem[0] = true; + } + + act[n - 1] = gcd(a[n - 1], a[n - 2]); + if (act[n - 1] > b[n - 1]) { + act[n - 1] = a[n - 1]; + } - // ll t = gcd(a[0], a[1]); - // if (t != a[0] && t <= b[0]) { - // a[0] = t; - // act++; - // } - // t = gcd(a[n - 1], a[n - 2]); - // if (t != a[n - 1] && t <= b[n - 1]) { - // a[n - 1] = t; - // act++; - // } + if (act[n - 1] != a[n - 1]) { + rem[n - 1] = true; + } - while (!pq.empty()) { - auto [bi, i] = pq.top(); - pq.pop(); - - ll g1 = i == n - 1 ? 1 : gcd(a[i], a[i + 1]); - ll g2 = i == 0 ? 1 : gcd(a[i], a[i - 1]); - ll bs = lcm(g1, g2); - - int low = 1; - int high = 1e9; - int ans = 0; - while (low <= high) { - int mid = (low + high) >> 1; - - if (bs * mid <= b[i]) { - ans = mid; - low = mid + 1; - continue; - } - - high = mid - 1; - } - - if (ans == 0) { + nrep(i, 1, n - 1) { + act[i] = lcm(gcd(a[i], a[i - 1]), gcd(a[i], a[i + 1])); + if (act[i] > b[i]) { + act[i] = a[i]; continue; } - ll t1 = i == n - 1 ? 1 : a[i + 1] / g1; - ll t2 = i == 0 ? 1 : a[i - 1] / g2; - // ll lc = lcm(t1, t2); - - // while (ans > 0 && (t1 % primes[ans] == 0 || t2 % primes[ans] == 0 || primes[ans] * bs == a[i])) { - // ans--; - // } - - if (ans % t1 == 0) { - ans /= t1; + if (act[i] != a[i]) { + rem[i] = true; } - - if (ans % t2 == 0) { - ans /= t2; - } - - act += bs * ans != a[i]; - a[i] = bs * ans; } - cout << act << '\n'; + vvl dp(n, vl(ps, -OO)); + dp[0][0] = rem[0]; + if (!rem[0]) { + rep(i, ps) { + ll cur = p[i] * act[0]; + if (cur > b[0]) { + break; + } + + dp[0][i] = (cur != a[0]); + } + } + + nrep(i, 1, n) { + ll bf = act[i - 1] / gcd(act[i - 1], act[i]); + ll nw = act[i] / gcd(act[i - 1], act[i]); + + if (rem[i]) { + dp[i][0] = dp[i - 1][0] + 1; + nrep(k, 1, ps) { + if (nw % p[k] != 0) { + rmax(dp[i][0], dp[i - 1][k] + 1); + } + } + continue; + } + + dp[i][0] = dp[i - 1][0]; + + nrep(k, 1, ps) { + if (nw % p[k] == 0) { + continue; + } + + rmax(dp[i][0], dp[i - 1][k]); + } + + nrep(j, 1, ps) { + if (act[i] * p[j] > b[i]) { + break; + } + if (bf % p[j] == 0) { + continue; + } + + rmax(dp[i][j], dp[i - 1][0] + (act[i] * p[j] != a[i])); + nrep(k, 1, ps) { + if (j == k || nw % p[k] == 0) { + continue; + } + + rmax(dp[i][j], dp[i - 1][k] + (act[i] * p[j] != a[i])); + } + } + } + + cout << max(*max_element(all(dp[n - 1])), 0LL) << '\n'; } int main() diff --git a/Codeforces Round 884 (Div. 1 + Div. 2)/D. Row Major.cpp b/Codeforces Round 884 (Div. 1 + Div. 2)/D. Row Major.cpp new file mode 100644 index 0000000..5f91be4 --- /dev/null +++ b/Codeforces Round 884 (Div. 1 + Div. 2)/D. Row Major.cpp @@ -0,0 +1,140 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1844/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 divs; + + for (int i = 1; i * i <= n; i++) { + if (n % i == 0) { + divs.push_back(i); + if (i * i != n) { + divs.push_back(n / i); + } + } + } + + sortv(divs); + int di = 1; + rep(i, n) { + if (divs[i] == di) { + di++; + continue; + } + + break; + } + + string ans(n, 'a'); + nrep(i, 1, n) { + if (i >= di) { + ans[i] = ans[i - di]; + continue; + } + ans[i] = i + 'a'; + } + + 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 892 (Div. 2)/D. Andrey and Escape from Capygrad.cpp b/Codeforces Round 892 (Div. 2)/D. Andrey and Escape from Capygrad.cpp new file mode 100644 index 0000000..d463e5c --- /dev/null +++ b/Codeforces Round 892 (Div. 2)/D. Andrey and Escape from Capygrad.cpp @@ -0,0 +1,199 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1859/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; + + V> ev; + V> act(n); + rep(i, n) { + ll l, r, a ,b; + cin >> l >> r >> a >> b; + + ev.emplace_back(a, 0, i); + ev.emplace_back(b, 1, i); + ev.emplace_back(l - 1, 2, i); + + act[i] = {l, r, a, b}; + } + + sort(all(ev), greater<>()); + vl best(n); + rep(i, n) { + best[i] = act[i][3]; + } + + V> all; + + multiset el; + for (auto [p, t, i] : ev) { + if (t == 1) { + el.insert(p); + continue; + } + + if (t == 2) { + all.emplace_back(act[i][0], act[i][3], best[i]); + el.erase(act[i][3]); + continue; + } + + if (t == 0) { + if (el.empty()) { + continue; + } + rmax(best[i], *prev(el.end())); + } + } + + sort(all(all), [&](tuple &i, tuple &j){ + auto [li, ri, bi] = i; + auto [lj, rj, bj] = j; + if (li == lj) { + return ri < rj; + } + return li < lj; + }); + + V> v; + auto [l, r, b] = all[0]; + nrep(i, 1, all.size()) { + auto [lu, ru, bu] = all[i]; + if (lu <= r && l <= ru) { + rmax(b, bu); + rmin(l, lu); + rmax(r, ru); + continue; + } + + v.emplace_back(l, r, b); + l = lu; + r = ru; + b = bu; + } + + v.emplace_back(l, r, b); + + int q; + cin >> q; + while (q--) { + ll x; + cin >> x; + + auto itr = upper_bound(all(v), tuple(x, 1e9, 1e9)); + if (itr == v.begin()) { + cout << x << ' '; + continue; + } + + itr--; + auto [l, r, b] = *itr; + if (r >= x) { + cout << max(x, b) << ' '; + continue; + } + cout << x << ' '; + } + 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 943 (Div. 3)/E. Cells Arrangement.cpp b/Codeforces Round 943 (Div. 3)/E. Cells Arrangement.cpp new file mode 100644 index 0000000..2e0ac68 --- /dev/null +++ b/Codeforces Round 943 (Div. 3)/E. Cells Arrangement.cpp @@ -0,0 +1,114 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1968/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; + + rep(i, n - 2) { + cout << (i + 1) << ' ' << (i + 1) << '\n'; + } + + cout << n - 1 << ' ' << n << '\n'; + cout << n << ' ' << n << '\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 7aa32c3..5193f8a 100644 --- a/TODO.md +++ b/TODO.md @@ -138,9 +138,14 @@ Official divs from codeforces Almost did it, I think I got what it needs to do it, but ran out of time. - - [ ] [C2. Equal Multisets (Hard Version)](https://codeforces.com/contest/2211/problem/C2) + - [X] [C2. Equal Multisets (Hard Version)](https://codeforces.com/contest/2211/problem/C2) I was finishing it, but then I got bored. + + - [ ] [I. Short Permutation Problem](https://codeforces.com/problemset/problem/1909/I) + + 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. - Div 3 diff --git a/Teza Round 1 (Codeforces Round 1015, Div. 1 + Div. 2)/D. Arcology On Permafrost.cpp b/Teza Round 1 (Codeforces Round 1015, Div. 1 + Div. 2)/D. Arcology On Permafrost.cpp new file mode 100644 index 0000000..0266231 --- /dev/null +++ b/Teza Round 1 (Codeforces Round 1015, Div. 1 + Div. 2)/D. Arcology On Permafrost.cpp @@ -0,0 +1,117 @@ +/* Problem URL: https://codeforces.com/problemset/problem/2084/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, k; + cin >> n >> m >> k; + + int mod = k; + while (n / (mod + 1) > m) { + mod++; + } + + rep(i, n) { + cout << i % mod << ' '; + } + 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/problemlist.md b/problemlist.md index edb4e2f..d1e7dca 100644 --- a/problemlist.md +++ b/problemlist.md @@ -113,7 +113,6 @@ A little collection of interesting problems that I randomly decided to do. it's a dp problem is already a challenge by itself. - ## Graph - [D. D/D/D](https://codeforces.com/problemset/problem/2109/D)