Idea: soullless
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
int x;
cin >> x;
int mn = 9;
while(x > 0) {
mn = min(mn, x % 10);
x/=10;
}
cout << mn << endl;
}
}
2126B - No Casino in the Mountains
Idea: soullless
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
int n,k;
cin >> n >> k;
int a[n + 1];
for(int i = 1;i <= n;i++) cin >> a[i];
int ans = 0;
int cnt = 0;
for(int i = 1;i <= n;i++) {
if(a[i] == 1) {
ans+=(cnt + 1)/(k + 1);
cnt = 0;
continue;
}
else {
cnt++;
}
}
ans+=(cnt + 1)/(k + 1);
cout << ans << endl;
}
}
2126C - I Will Definitely Make It
Idea: soullless
~~~~~
include <bits/stdc++.h>
using namespace std; int main() { int t; cin >> t; while(t--) { int n,p; cin >> n >> p; int a[n + 1]; for(int i = 1;i <= n;i++) cin >> a[i]; int cur = a[p]; int dist = a[p]; sort(a + 1,a + n + 1); bool ans = true; for(int i = 1;i <= n;i++) { if(a[i] < cur) continue; if(a[i] — cur > dist) { ans = false; } cur = a[i]; } if(ans) cout << "YES" << endl; else cout << "NO" << endl; } } ы~~~~~
Idea: soullless
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
int n,k;
cin >> n >> k;
pair <int,pair <int,int> > p[n + 1];
for(int i = 1;i <= n;i++) cin >> p[i].first >> p[ыi].second.first >> p[i].second.second;
sort(p + 1,p + n + 1);
int cur = k;
for(int i = 1;i <= n;i++) {
if(p[i].first > cur) break;
cur = max(cur,p[i].second.second);
}
cout << cur << endl;
}
}
Idea: Away_in_the_heavens
~~~~~
include <bits/stdc++.h>
using namespace std; main() { int t; cin >> t; while (t--) { int n; cin >> n; long long a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } long long b[n + 1]; for (int i = 1; i <= n; i++) { cin >> b[i]; } long long ans[n + 1]; for (int i = n; i >= 1; i--) { ans[i] = lcm(a[i], b[i]); } bool ch = 1; if(ans[1] != a[1]) ch = 0; if(ans[n] != b[n]) ch = 0; for (int i = 2; i <= n; i++) { if (__gcd(a[i — 1], ans[i]) != a[i]) { ch = 0; } } for (int i = n — 1; i >= 1; i--) { if (__gcd(b[i + 1], ans[i]) != b[i]) { ch = 0; } } if (ch) { cout << "YES" << "\n"; } else { cout << "NO" << "\n"; } } }~~~~~
Idea: soullless
#include <bits/stdc++.h>
using namespace std;
const int B = 2e5 + 100;
int n;
int col[B];
long long costt = 0;
vector <pair <int,int> > reb[B];
bool was[B];
map <int,long long> cnt[B];
int pred[B];
long long zn[B];
void dfs(int v) {
was[v] = true;
for(auto u:reb[v]) {
if(was[u.first]) {
pred[v] = u.first;
continue;
}
if(col[v] != col[u.first]) costt+=u.second;
dfs(u.first);
zn[u.first] = u.second;
cnt[v][col[u.first]]+=zn[u.first];
}
}
void update(int v,int x) {
if(v != 1) {
cnt[pred[v]][col[v]]-=zn[v];
if(col[pred[v]] == col[v]) costt+=zn[v];
cnt[pred[v]][x]+=zn[v];
if(col[pred[v]] == x) costt-=zn[v];
}
else {
}
costt+=cnt[v][col[v]];
costt-=cnt[v][x];
col[v] = x;
}
void clr() {
for(int i = 1;i <= n;i++) {
reb[i].clear();
was[i] = false;
cnt[i].clear();
zn[i] = 0;
}
costt = 0;
}
int main() {
int t;
cin >> t;
while(t--) {
int q;
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> col[i];
for(int i = 1; i < n; i++) {
int u, v, c;
cin >> u >> v >> c;
reb[v].push_back({u,c});
reb[u].push_back({v,c});
}
dfs(1);
while(q--) {
int pos,x;
cin >> pos >> x;
update(pos,x);
cout << costt << "\n";
}
clr();
}
}
2126G1 - Big Wins! (easy version)
Idea: soullless
#include <bits/stdc++.h>
using namespace std;
const int B = 2e5 + 100;
int main() {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
int a[n + 1];
for(int i = 1;i <= n;i++) cin >> a[i];
int ans = 0;
for(int i = 1;i <= 100;i++) {
int b[n + 1] = {};
for(int j = 1;j <= n;j++) {
if(a[j] >= i) b[j] = 1;
else b[j] = -1;
}
int pref[n + 1] = {};
for(int j = 1; j <= n; j++) {
pref[j] = pref[j - 1] + b[j];
}
int prefmn[n + 2] = {},suffmx[n + 1] = {};
prefmn[0] = 0,suffmx[n] = pref[n];
for(int j = 1; j <= n; j++) {
prefmn[j] = min(prefmn[j - 1],pref[j]);
}
for(int j = n - 1; j >= 1; j--) {
suffmx[j] = max(suffmx[j + 1],pref[j]);
}
for(int j = 1; j <= n; j++) {
if(prefmn[j - 1] <= pref[j] || pref[j - 1] <= suffmx[j]) {
ans = max(ans,i - a[j]);
}
}
}
cout << ans << endl;
}
}
2126G2 - Big Wins! (hard version)
Idea: soullless
~~~~~
include<bits/stdc++.h>
using namespace std; int n; int a[200005 + 2]; array<int, 4> t[800005]; array<int, 4> merge(array<int, 4>a, array<int, 4>b) { int ans = max(a[0], b[0]); int mxpref = max(a[1], a[3] + b[1]); int mxsuff = max(b[2], a[2] + b[3]); ans = max({ans, mxpref, mxsuff}); int sum = a[3] + b[3]; return {ans, mxpref, mxsuff, sum}; } void update(int v, int tl, int tr, int pos, int val) { if (tl == tr) { t[v] = {max(val, 0), max(val, 0), max(val, 0), val}; } else { int tm = (tl + tr) >> 1; if (pos <= tm) { update(v * 2, tl, tm, pos, val); } else { update(v * 2 + 1, tm + 1, tr, pos, val); } t[v] = merge(t[v * 2], t[v * 2 + 1]); } } array<int, 4> get(int v, int tl, int tr, int l, int r) { if (tl == l && tr == r) { return t[v]; } else if (l > r) { return {0, 0, 0, 0}; } else { int tm = (tl + tr) >> 1; return merge(get(v * 2, tl, tm, l, min(r, tm)), get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)); } } int solve(int n, vectorA) { int m = 0; for (int i = 1; i <= n; i++) { a[i] = A[i — 1]; m = max(m, a[i]); } vectorind[m + 1]; for (int i = 1; i <= n; i++) { ind[a[i]].push_back(i); } stacks; s.push(0); a[0] = -INT_MAX; int l[n + 1]; for (int i = 1; i <= n; i++) { while (a[s.top()] >= a[i]) { s.pop(); } l[i] = s.top() + 1; s.push(i); } a[n + 1] = -INT_MAX; s.push(n + 1); int r[n + 1]; for (int i = n; i >= 1; i--) { while (a[s.top()] >= a[i]) { s.pop(); } r[i] = s.top() — 1; s.push(i); } int med = 1; for (int i = 1; i <= n; i++) { update(1, 1, n, i, 1); } for (auto u : ind[1]) { update(1, 1, n, u, -1); } int ans = 0; for (int mn = 1; mn <= m; mn++) { for (auto u : ind[mn]) { int lg = l[u], rg = r[u]; while (med < m && get(1, 1, n, lg, u — 1)[2] + get(1, 1, n, u + 1, rg)[1] + (a[u] < (med) ? -1 : 1) >= 0) { med++; for (auto u : ind[med]) { update(1, 1, n, u, -1); } } } // cout << med << ' ' << mn << endl; ans = max(ans, med — mn); } return ans; } int solveslow(int n, vectorA) { for (int i = 1; i <= n; i++) { a[i] = A[i — 1]; } int mx = 0; for (int i = 1; i <= n; i++) { vectorv; for (int j = i; j <= n; j++) { v.push_back(a[j]); sort(v.begin(), v.end()); mx = max(mx, v[v.size() / 2] — v[0]); } } return mx; } int rnd() { return (rand() + rand() * RAND_MAX); } main() { ios_base::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while(tt--) { int n; cin >> n; vectorv; for (int i = 1; i <= n; i++) { int x; cin >> x; v.push_back(x); } cout << solve(n, v) << endl; // cout << solveslow(n, v) << endl; for(int i = 0;i <= n*4;i++) { t[i][0] = 0; t[i][1] = 0; t[i][2] = 0; t[i][3] = 0; } } }~~~~~



