Add a bunch of other problems

This commit is contained in:
2025-10-01 10:35:36 -03:00
parent 489cb2ba51
commit e3421b4066
71 changed files with 9894 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
/* Problem URL: https://codeforces.com/contest/598/problem/A */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
ll ans = n * (n + 1) / 2;
ll now = 1;
while (now <= n) {
ans -= now * 2;
now <<= 1;
}
cout << ans << '\n';
}
}

View File

@@ -0,0 +1,102 @@
/* Problem URL: https://codeforces.com/contest/598/problem/B */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
int m;
cin >> m;
while (m--) {
int l, r, k;
cin >> l >> r >> k;
l--, r--;
k = (k - 1) % (r - l + 1) + 1;
string ans = s.substr(r - k + 1, k) + s.substr(l, (r - l + 1) - k);
rep(i, ans.size()) {
s[l + i] = ans[i];
}
}
cout << s << '\n';
}

View File

@@ -0,0 +1,183 @@
/* Problem URL: https://codeforces.com/contest/598/problem/C */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
#define sq(x) ((x)*(ll)(x))
struct pt { // ponto
ll x, y;
pt(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
bool operator < (const pt p) const {
if (x != p.x) return x < p.x;
return y < p.y;
}
bool operator == (const pt p) const {
return x == p.x and y == p.y;
}
pt operator + (const pt p) const { return pt(x+p.x, y+p.y); }
pt operator - (const pt p) const { return pt(x-p.x, y-p.y); }
pt operator * (const int c) const { return pt(x*c, y*c); }
ll operator * (const pt p) const { return x*(ll)p.x + y*(ll)p.y; }
ll operator ^ (const pt p) const { return x*(ll)p.y - y*(ll)p.x; }
friend istream& operator >> (istream& in, pt& p) {
return in >> p.x >> p.y;
}
};
struct line { // reta
pt p, q;
line() {}
line(pt p_, pt q_) : p(p_), q(q_) {}
friend istream& operator >> (istream& in, line& r) {
return in >> r.p >> r.q;
}
};
// PONTO & VETOR
ll dist2(pt p, pt q) { // quadrado da distancia
return sq(p.x - q.x) + sq(p.y - q.y);
}
ll sarea2(pt p, pt q, pt r) { // 2 * area com sinal
return (q-p)^(r-q);
}
bool col(pt p, pt q, pt r) { // se p, q e r sao colin.
return sarea2(p, q, r) == 0;
}
bool ccw(pt p, pt q, pt r) { // se p, q, r sao ccw
return sarea2(p, q, r) > 0;
}
int quad(pt p) { // quadrante de um ponto
return (p.x<0)^3*(p.y<0);
}
bool compare_angle(pt p, pt q) { // retorna se ang(p) < ang(q)
if (quad(p) != quad(q)) return quad(p) < quad(q);
return ccw(q, pt(0, 0), p);
}
pt rotate90(pt p) { // rotaciona 90 graus
return pt(-p.y, p.x);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
V<pair<pt, int>> fds(n);
rep(i, n) {
cin >> fds[i].first;
fds[i].second = i + 1;
}
sort(all(fds), [&](pair<pt, int> &a, pair<pt, int> &b) {
return compare_angle(a.first, b.first);
});
auto better = [&](pt &a, pt &b, pt &c, pt &d) {
pt p1(a * b, abs(a ^ b));
pt p2(c * d, abs(c ^ d));
return (p1 ^ p2) > 0;
};
int ans1 = 0;
int ans2 = 1;
nrep(i, 1, n - 1) {
pt &one = fds[i].first;
pt &two = fds[i + 1].first;
if (better(one, two, fds[ans1].first, fds[ans2].first)) {
ans1 = i;
ans2 = i + 1;
}
}
pt &one = fds.back().first;
pt &two = fds[0].first;
if (better(one, two, fds[ans1].first, fds[ans2].first)) {
ans1 = n - 1;
ans2 = 0;
}
cout << fds[ans1].second << ' ' << fds[ans2].second << '\n';
}

View File

@@ -0,0 +1,142 @@
/* Problem URL: https://codeforces.com/contest/598/problem/D */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
V<string> fds(n);
cin >> fds;
V<V<bool>> vis(n, V<bool>(m));
function<int(int, int)> dfs = [&](int i, int j) {
if (fds[i][j] == '*') {
return 1;
}
vis[i][j] = true;
int ans = 0;
int add[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
repv(k, add) {
int id = i + k[0];
int jd = j + k[1];
if (id >= 0 && id < n && jd >= 0 && jd < m && !vis[id][jd]) {
ans += dfs(id, jd);
}
}
return ans;
};
vvi ans(n, vi(m));
function<void(int, int, int)> flood = [&](int i, int j, int v) {
fds[i][j] = '*';
ans[i][j] = v;
int add[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
repv(k, add) {
int id = i + k[0];
int jd = j + k[1];
if (id >= 0 && id < n && jd >= 0 && jd < m && fds[id][jd] == '.') {
flood(id, jd, v);
}
}
};
rep(i, n) {
rep(j, m) {
if (fds[i][j] == '.' && !vis[i][j]) {
int tmp = dfs(i, j);
flood(i, j, tmp);
}
}
}
while (k--) {
int i, j;
cin >> i >> j;
cout << ans[i - 1][j - 1] << '\n';
}
}