diff --git a/Codeforces Round 1089 (Div. 2)/A. A Simple Sequence.cpp b/Codeforces Round 1089 (Div. 2)/A. A Simple Sequence.cpp new file mode 100644 index 0000000..2fb8e53 --- /dev/null +++ b/Codeforces Round 1089 (Div. 2)/A. A Simple Sequence.cpp @@ -0,0 +1,112 @@ +/* Problem URL: https://codeforces.com/contest/2210/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; + cin >> n; + + rep(i, n) { + cout << n - 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)/B. Simply Sitting on Chairs.cpp b/Codeforces Round 1089 (Div. 2)/B. Simply Sitting on Chairs.cpp new file mode 100644 index 0000000..1f3bae7 --- /dev/null +++ b/Codeforces Round 1089 (Div. 2)/B. Simply Sitting on Chairs.cpp @@ -0,0 +1,118 @@ +/* Problem URL: https://codeforces.com/contest/2210/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; + cin >> n; + vi p(n); + cin >> p; + + int ans = 0; + rep(i, n) { + if (p[i] - 1 <= i) { + ans++; + } + } + + 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 1089 (Div. 2)/C1. A Simple GCD Problem (Easy Version).cpp b/Codeforces Round 1089 (Div. 2)/C1. A Simple GCD Problem (Easy Version).cpp new file mode 100644 index 0000000..fa439ec --- /dev/null +++ b/Codeforces Round 1089 (Div. 2)/C1. A Simple GCD Problem (Easy Version).cpp @@ -0,0 +1,134 @@ +/* Problem URL: https://codeforces.com/contest/2210/problem/C1 */ + +#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); + vl b(n); + cin >> a >> b; + + ll t = gcd(a[0], a[1]); + int ans = 0; + + if (a[0] != t) { + ans++; + } + + t = gcd(a[n - 1], a[n - 2]); + if (a[n - 1] != t) { + ans++; + } + + nrep(i, 1, n - 1) { + ll g1 = gcd(a[i], a[i - 1]); + ll g2 = gcd(a[i], a[i + 1]); + + ll lc = lcm(g1, g2); + if (lc < a[i]) { + ans++; + } + } + + 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 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 new file mode 100644 index 0000000..5a81c56 --- /dev/null +++ b/Codeforces Round 1089 (Div. 2)/C2. A Simple GCD Problem (Hard Version).cpp @@ -0,0 +1,215 @@ +/* Problem URL: https://codeforces.com/contest/2210/problem/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; + +constexpr int MAXN = 5e4 + 10; +int di[MAXN]; +vi divs[MAXN]; +vi primes; + +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 + +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); + } + + int act = 0; + + // 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++; + // } + + 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) { + 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 (ans % t2 == 0) { + ans /= t2; + } + + act += bs * ans != a[i]; + a[i] = bs * ans; + } + + cout << act << '\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)/D. A Simple RBS Problem.cpp b/Codeforces Round 1089 (Div. 2)/D. A Simple RBS Problem.cpp new file mode 100644 index 0000000..c3f1a02 --- /dev/null +++ b/Codeforces Round 1089 (Div. 2)/D. A Simple RBS Problem.cpp @@ -0,0 +1,153 @@ +/* Problem URL: https://codeforces.com/contest/2210/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 1 + +void solve() +{ + int n; + cin >> n; + string a, b; + cin >> a >> b; + + auto calc = [&](string &a) -> tuple { + int c1 = 0; + int c2 = 0; + int lvl = 0; + bool val = false; + stack s; + s.push(0); + rep(i, n) { + if (a[i] == '(') { + s.top()++; + s.push(0); + continue; + } + + int c = s.top(); + s.pop(); + + c1 += c != 0; + c2 += c == 0; + val = val || c >= 2; + if (c == 1) { + lvl++; + } else { + lvl = 0; + } + } + + c1 += s.top() != 0; + c2 += s.top() == 0; + val = val || s.top() >= 2; + if (s.top() == 1) { + lvl++; + } else { + lvl = 0; + } + + return {c1, c2, val, lvl}; + }; + + auto ca = calc(a); + auto cb = calc(b); + + cout << (ca == cb ? "YES\n" : "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 945 (Div. 2)/A. Chess For Three.cpp b/Codeforces Round 945 (Div. 2)/A. Chess For Three.cpp new file mode 100644 index 0000000..4d2a819 --- /dev/null +++ b/Codeforces Round 945 (Div. 2)/A. Chess For Three.cpp @@ -0,0 +1,129 @@ +/* Problem URL: https://codeforces.com/contest/1973/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() +{ + array a; + cin >> a[0] >> a[1] >> a[2]; + sort(all(a), greater<>()); + + if (count(all(a), 0) == 3) { + cout << "0\n"; + return; + } + + int c = (a[0] & 1) + (a[1] & 1) + (a[2] & 1); + if (c == 3 || c == 1) { + cout << "-1\n"; + return; + } + + int ans = 0; + while (a[0] && (a[1] || a[2])) { + a[0]--; + a[1]--; + ans++; + sort(all(a), greater<>()); + } + + 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/Good Bye 2019/E. Divide Points.cpp b/Good Bye 2019/E. Divide Points.cpp new file mode 100644 index 0000000..1e6d5f6 --- /dev/null +++ b/Good Bye 2019/E. Divide Points.cpp @@ -0,0 +1,171 @@ +/* Problem URL: https://codeforces.com/problemset/problem/1270/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; + +struct pt { + ll x, y; + + pt() = default; + pt(ll x, ll y): x(x), y(y) {} + + friend istream &operator >> (istream &is, pt &a) { + is >> a.x >> a.y; + return is; + } +}; + +void pre() +{ + +} + +#define TEST 0 + +void solve() +{ + int n; + cin >> n; + + V a(n); + cin >> a; + + auto check = [&]() { + set> c; + repv(i, a) { + c.emplace(i.x & 1, i.y & 1); + } + + if (c.size() == 1) { + return true; + } + + return false; + }; + + while (check()) { + nrep(i, 1, n) { + a[i] = pt((a[i].x - a[0].x) / 2 + a[0].x, (a[i].y - a[0].y) / 2 + a[0].y); + } + } + + map, vi> c; + rep(i, n) { + c[{a[i].x & 1, a[i].y & 1}].push_back(i + 1); + } + + if ((c.count({0, 0}) || c.count({1, 1})) && (c.count({1, 0}) || c.count({0, 1}))) { + auto v1 = c[{0, 0}]; + auto v2 = c[{1, 1}]; + + cout << v1.size() + v2.size() << '\n'; + repv(i, v1) { + cout << i << ' '; + } + repv(i, v2) { + cout << i << ' '; + } + cout << '\n'; + return; + } + + auto v1 = c[{0, 0}]; + auto v2 = c[{0, 1}]; + cout << v1.size() + v2.size() << '\n'; + repv(i, v1) { + cout << i << ' '; + } + repv(i, v2) { + cout << 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/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/A. Antimedian Deletion.cpp b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/A. Antimedian Deletion.cpp new file mode 100644 index 0000000..271f555 --- /dev/null +++ b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/A. Antimedian Deletion.cpp @@ -0,0 +1,118 @@ +/* Problem URL: https://codeforces.com/contest/2211/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; + cin >> n; + vi p(n); + cin >> p; + + if (n == 1) { + cout << "1\n"; + return; + } + + rep(i, n) { + cout << "2" << " \n"[i == n - 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/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/B. Mickey Mouse Constructive.cpp b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/B. Mickey Mouse Constructive.cpp new file mode 100644 index 0000000..7e6fbf2 --- /dev/null +++ b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/B. Mickey Mouse Constructive.cpp @@ -0,0 +1,132 @@ +/* Problem URL: https://codeforces.com/contest/2211/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 x, y; + cin >> x >> y; + int n = x + y; + + auto getdivs = [&](int n) { + int ans = 0; + for (int i = 1; i * i <= n; i++) { + if (n % i == 0) { + ans++; + if (i * i != n) { + ans++; + } + } + } + + return ans; + }; + + int diff = max(abs(x - y), 1); + cout << getdivs(diff) << '\n'; + while (x--) { + cout << "1 "; + } + while (y--) { + cout << "-1 "; + } + 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/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/C1. Equal Multisets (Easy Version).cpp b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/C1. Equal Multisets (Easy Version).cpp new file mode 100644 index 0000000..9bd8442 --- /dev/null +++ b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/C1. Equal Multisets (Easy Version).cpp @@ -0,0 +1,155 @@ +/* Problem URL: https://codeforces.com/contest/2211/problem/C1 */ + +#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); + vi b(n); + cin >> a >> b; + + set c; + set val; + int c1 = 0; + vi pos(n, -1); + rep(i, n) { + if (b[i] != -1) { + c1++; + c.insert(b[i]); + pos[b[i] - 1] = i; + continue; + } + + val.insert(i); + } + + if (c.size() != c1) { + cout << "NO\n"; + return; + } + + rep(i, n) { + int l = min(i + k, n) - k; + int r = max(i - k, -1) + k; + int cur = a[i] - 1; + + if (pos[cur] != -1) { + if (pos[cur] > r || pos[cur] < l) { + cout << "NO\n"; + return; + } + continue; + } + + auto itr = val.lower_bound(l); + if (itr == val.end() || *itr > r) { + cout << "NO\n"; + return; + } + + val.erase(itr); + } + + 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/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/C2. Equal Multisets (Hard Version).cpp b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/C2. Equal Multisets (Hard Version).cpp new file mode 100644 index 0000000..2659fe6 --- /dev/null +++ b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/C2. Equal Multisets (Hard Version).cpp @@ -0,0 +1,199 @@ +/* Problem URL: https://codeforces.com/contest/2211/problem/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, k; + cin >> n >> k; + + vi a(n); + vi b(n); + cin >> a >> b; + + auto test = [&]() { + multiset s; + int c = 0; + rep(i, k) { + if (b[i] == -1) { + c++; + continue; + } + + s.insert(b[i]); + } + + rep(i, k) { + if (s.find(a[i]) == s.end()) { + if (c) { + c--; + continue; + } + + return false; + } + + s.erase(s.find(a[i])); + } + + return true; + }; + + if (!test()) { + cout << "NO\n"; + return; + } + + V>> vec(k); + + for (int i = 0; i < n; i++) { + vec[i % k].emplace_back(a[i], b[i]); + } + + vi c1(n); + vi c2(n); + + repv(now, vec) { + set c; + repv(j, now) { + c.insert(j.first); + } + + if (c.size() == 1) { + c1[*c.begin() - 1]++; + set ot; + repv(j, now) { + if (j.second == -1) { + continue; + } + ot.insert(j.second); + } + + if (ot.empty()) { + continue; + } + + if (ot.size() > 1) { + cout << "NO\n"; + return; + } + + c2[*ot.begin() - 1]++; + continue; + } + + repv(j, now) { + if (j.second != -1 && j.second != j.first) { + cout << "NO\n"; + return; + } + } + } + + rep(i, n) { + if (c2[i] > c1[i]) { + 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/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/D. AND-array.cpp b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/D. AND-array.cpp new file mode 100644 index 0000000..1ae79cc --- /dev/null +++ b/Nebius Round 2 (Codeforces Round 1088, Div. 1 + Div. 2)/D. AND-array.cpp @@ -0,0 +1,155 @@ +/* Problem URL: https://codeforces.com/contest/2211/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; + +const ll mod = 1e9 + 7; +constexpr int MAXN = 2e5; +ll fact[MAXN]; +ll inv[MAXN]; +ll finv[MAXN]; + +void pre() +{ + fact[0] = 1; + nrep(i, 1, MAXN) { + fact[i] = fact[i - 1] * i % mod; + } + + inv[1] = 1; + nrep(i, 2, MAXN) { + inv[i] = (mod - mod / i) * inv[mod % i] % mod; + } + + finv[0] = 1; + nrep(i, 1, MAXN) { + finv[i] = finv[i - 1] * inv[i] % mod; + } +} + +ll comb(ll n, ll k) +{ + return fact[n] * finv[k] % mod * finv[n - k] % mod; +} + +#define TEST 1 + +void solve() +{ + int n; + cin >> n; + + vl b(n); + cin >> b; + reverse(all(b)); + + vl ans(n); + + rep(i, n) { + rep(j, 29) { + if (((b[i] >> j) & 1) == 0) { + continue; + } + + nrep(k, i, n) { + ans[k] |= 1 << j; + } + + nrep(k, i + 1, n) { + b[k] -= (1LL << j) * comb(n - i, n - k); + b[k] = (b[k] % mod + mod) % mod; + } + } + } + + cout << ans; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + pre(); + + int t; + (TEST && cin >> t) || (t = 1); + while (t--) { + solve(); + } +} diff --git a/TODO.md b/TODO.md index d804fb9..7aa32c3 100644 --- a/TODO.md +++ b/TODO.md @@ -137,6 +137,10 @@ Official divs from codeforces - [X] [D. Survey in Class](https://codeforces.com/problemset/problem/1834/D) 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) + + I was finishing it, but then I got bored. - Div 3