Add a bunch of other problems.

Some are not finished...
This commit is contained in:
2025-09-12 14:50:25 -03:00
parent 88e542c982
commit 489cb2ba51
385 changed files with 49442 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
/* Problem URL: https://codeforces.com/contest/2132/problem/0 */
#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--) {
int n;
cin >> n;
string a;
cin >> a;
int m;
cin >> m;
string b;
cin >> b;
string c;
cin >> c;
string ans1;
string ans2;
rep(i, m) {
if (c[i] == 'V') {
ans1.push_back(b[i]);
} else {
ans2.push_back(b[i]);
}
}
reverse(all(ans1));
cout << ans1 << a << ans2 << '\n';
}
}

View File

@@ -0,0 +1,110 @@
/* Problem URL: https://codeforces.com/contest/2132/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);
int t;
cin >> t;
while (t--) {
ll x;
cin >> x;
ll div = 10;
set<ll> ans;
while (div <= x) {
if (x % (div + 1) == 0) {
ans.insert(x / (div + 1));
}
div *= 10;
}
cout << ans.size() << '\n';
if (ans.empty()) {
continue;
}
for (auto &i : ans) {
cout << i << ' ';
}
cout << '\n';
}
}

View File

@@ -0,0 +1,110 @@
/* Problem URL: https://codeforces.com/contest/2132/problem/C1 */
#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);
vl pows(21);
pows[0] = 1;
nrep(i, 1, 21) {
pows[i] = pows[i - 1] * 3;
}
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
ll ans = 0;
while (n > 0) {
ll now = 0;
while (pows[now + 1] <= n) {
now++;
}
n -= pows[now];
ans += pows[now + 1] + pows[max(now - 1, 0LL)] * now;
}
cout << ans << '\n';
}
}

View File

@@ -0,0 +1,145 @@
/* Problem URL: https://codeforces.com/contest/2132/problem/C2 */
#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);
vl pows(21);
pows[0] = 1;
nrep(i, 1, 21) {
pows[i] = pows[i - 1] * 3;
}
int t;
cin >> t;
while (t--) {
ll n, k;
cin >> n >> k;
vi count(21);
ll now = 20;
ll total = 0;
while (now >= 0) {
count[now] = n / pows[now];
total += count[now];
n %= pows[now];
now--;
}
if (total > k) {
cout << "-1\n";
continue;
}
for (int j = 20; j > 0; j--) {
for (int i = j - 1; i >= 0; i--) {
int low = 0;
int high = count[j];
ll ans = 0;
while (low <= high) {
int mid = (low + high) >> 1;
if (total - mid + (pows[j] / pows[i]) * mid <= k) {
ans = mid;
low = mid + 1;
continue;
}
high = mid - 1;
}
total -= ans;
total += ans * (pows[j] / pows[i]);
count[j] -= ans;
count[i] += ans * (pows[j] / pows[i]);
}
}
ll ans = 0;
rep(i, 20) {
ans += count[i] * (pows[i + 1] + pows[max(0LL, (ll)i - 1)] * i);
}
cout << ans << '\n';
}
}

View File

@@ -0,0 +1,120 @@
/* Problem URL: https://codeforces.com/contest/2132/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 q;
cin >> q;
while (q--) {
ll k;
cin >> k;
k--;
ll now = 1;
int digs = 1;
while (k >= digs * now * 9) {
k -= digs * now * 9;
now *= 10;
digs++;
}
ll act = now;
act += (k / digs);
k %= digs;
ll ans = 0;
ll prev = 0;
rep(i, digs) {
ll dig = act / now % 10;
ans += dig * (2 * prev + dig - 1) / 2 * now;
ans += dig * (digs - i - 1) * 45 * (now / 10);
prev += dig;
now /= 10;
}
string fds = to_string(act);
rep(i, k + 1) {
ans += fds[i] - '0';
}
cout << ans << '\n';
}
}

View File

@@ -0,0 +1,147 @@
/* Problem URL: https://codeforces.com/contest/2132/problem/E */
#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--) {
int n, m, q;
cin >> n >> m >> q;
vl af(n);
vl bf(m);
cin >> af >> bf;
vl a(n + 1);
vl b(m + 1);
sort(all(af), greater<>());
sort(all(bf), greater<>());
rep(i, n) {
a[i + 1] = a[i] + af[i];
}
rep(i, m) {
b[i + 1] = b[i] + bf[i];
}
while (q--) {
int x, y, z;
cin >> x >> y >> z;
ll ans = 0;
ll low = 0;
ll high = min(x, z);
while ((high - low) >= 3) {
ll third = (high - low) / 3;
ll mid1 = low + third;
ll mid2 = high - third;
ll ans1 = a[mid1] + b[max(min(z - mid1, (ll)y), 0LL)];
ll ans2 = a[mid2] + b[max(min(z - mid2, (ll)y), 0LL)];
ans = max({ans, ans1, ans2});
if (ans1 > ans2) {
high = mid2 - 1;
continue;
}
if (ans2 > ans1) {
low = mid1 + 1;
continue;
}
low = mid1 + 1;
high = mid2 - 1;
}
nrep(i, low, high + 1) {
rmax(ans, a[i] + b[max(min(z - (ll)i, (ll)y), 0LL)]);
}
cout << ans << '\n';
}
}
}

View File

@@ -0,0 +1,223 @@
/* Problem URL: https://codeforces.com/contest/2132/problem/F */
#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--) {
int n, m;
cin >> n >> m;
V<V<pair<int, int>>> graph(n);
rep(i, m) {
int a, b;
cin >> a >> b;
a--, b--;
graph[a].emplace_back(b, i);
graph[b].emplace_back(a, i);
}
V<V<pair<int, int>>> tree(n);
int inf = INT32_MAX >> 1;
int t = 0;
vi low(n, inf);
vi time(n, inf);
V<bool> vis(n);
V<bool> bridge(m);
vi ans(n, inf);
function<void(int, int)> dfs = [&](int i, int p) {
low[i] = t;
time[i] = t;
t++;
vis[i] = true;
for (auto [j, id] : graph[i]) {
if (j == p) {
continue;
}
if (vis[j]) {
rmin(low[i], time[j]);
continue;
}
dfs(j, i);
tree[i].emplace_back(j, id);
rmin(low[i], low[j]);
if (low[j] > time[i]) {
bridge[id] = true;
}
}
};
dfs(0, -1);
vi tmp;
function<bool(int)> search = [&](int i) {
if (i == n - 1) {
return true;
}
for (auto [j, id] : tree[i]) {
if (search(j)) {
if (bridge[id]) {
tmp.push_back(i);
tmp.push_back(j);
rmin(ans[i], id);
rmin(ans[j], id);
}
return true;
}
}
return false;
};
search(0);
set<pair<int, int>> fds;
repv(i, tmp) {
fds.emplace(ans[i], i);
}
int q;
cin >> q;
if (tmp.empty()) {
while (q--) {
int t;
cin >> t;
cout << "-1 ";
}
cout << '\n';
continue;
}
auto getans = [&]() {
queue<int> q;
vi level(n, inf);
for (auto [id, i] : fds) {
q.push(i);
level[i] = 0;
}
while (!q.empty()) {
int i = q.front();
q.pop();
for (auto [j, id] : graph[i]) {
if (level[j] > level[i] + 1) {
level[j] = level[i] + 1;
ans[j] = ans[i];
q.push(j);
continue;
}
if (level[j] == level[i] + 1) {
rmin(ans[j], ans[i]);
}
}
}
};
getans();
while (q--) {
int x;
cin >> x;
cout << ans[x - 1] + 1 << ' ';
}
cout << '\n';
}
}