Idea: fcspartakm
Tutorial
Tutorial is loading...
Solution (awoo)
for _ in range(int(input())):
a, b, c = map(int, input().split())
if (a + b + c) % 3 != 0:
print("NO")
continue
x = (a + b + c) // 3
print("YES" if b <= x else "NO")
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int i = 0; i < t; i++)
{
int n;
cin >> n;
vector<int> a(n);
for(int j = 0; j < n; j++) cin >> a[j];
vector<int> pmax(n + 1);
vector<long long> psum(n + 1);
for(int j = 0; j < n; j++)
{
pmax[j + 1] = max(pmax[j], a[j]);
psum[j + 1] = psum[j] + a[j];
}
for(int k = 1; k <= n; k++)
cout << pmax[n - k + 1] + psum[n] - psum[n - k + 1] << " ";
cout << endl;
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
def beats(n, x, y):
if x == 0:
return y == n - 1
if x == n - 1:
return y != 0
return x > y
for _ in range(int(input())):
n = int(input())
owner = input()
good = False
for i in range(n):
if owner[i] != 'A':
continue
good_move = True
for j in range(n):
if owner[j] == 'B' and beats(n, j, i):
good_move = False
if good_move:
good = True
if good:
print('Alice')
else:
print('Bob')
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
const int N = 6e6;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
vector<int> p, ip(N, 1);
for (int i = 2; i < N; ++i) {
if (!ip[i]) continue;
p.push_back(i);
for (int j = i; j < N; j += i) {
ip[j] = 0;
}
}
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (auto& x : a) cin >> x;
sort(a.begin(), a.end(), greater<int>());
int ans = 0;
long long suma = 0, sump = 0;
for (int i = 0; i < n; ++i) {
suma += a[i];
sump += p[i];
if (suma >= sump) ans = i + 1;
}
cout << n - ans << endl;
}
}
Idea: adedalic
Tutorial
Tutorial is loading...
Solution (adedalic)
#include<bits/stdc++.h>
using namespace std;
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) int((a).size())
#define x first
#define y second
typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
return out << "(" << p.x << ", " << p.y << ")";
}
template<class A> ostream& operator <<(ostream& out, const vector<A> &v) {
fore(i, 0, sz(v)) {
if(i) out << " ";
out << v[i];
}
return out;
}
const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;
int n, k;
string s;
inline bool read() {
if(!(cin >> n >> k))
return false;
cin >> s;
return true;
}
inline void solve() {
vector<int> d(n + 1, 0);
vector<vector<int>> nxt(n + 2, vector<int>(k, n));
for (int i = n - 1; i >= 0; i--) {
nxt[i] = nxt[i + 1];
int mx = *max_element(nxt[i].begin(), nxt[i].end());
d[i] = 1 + d[mx];
nxt[i][s[i] - 'a'] = i;
}
int q; cin >> q;
while (q--) {
string t; cin >> t;
int pos = -1;
for (char c : t)
pos = nxt[pos + 1][c - 'a'];
cout << d[pos] << "\n";
}
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
int tt = clock();
#endif
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
if(read()) {
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
return 0;
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
const long long A = (long long)(1e18);
string S(long long x)
{
string s = to_string(x) + to_string(x + 1);
sort(s.begin(), s.end());
return s;
}
vector<long long> aux2;
vector<pair<string, long long>> aux;
long long get_num(string cur)
{
int first_non_zero = 0;
while(cur[first_non_zero] == '0') first_non_zero++;
swap(cur[first_non_zero], cur[0]);
return stoll(cur);
}
void rec(string cur, bool flag)
{
if(*max_element(cur.begin(), cur.end()) > '0')
{
long long x = get_num(cur);
aux.push_back(make_pair(S(x), x));
}
if(cur.size() < 9)
{
if(flag)
rec(cur + "9", true);
else
for(char c = '0'; c <= '9'; c++)
rec(cur + string(1, c), c < cur.back());
}
}
void precalc()
{
for(char c = '0'; c <= '9'; c++)
rec(string(1, c), false);
sort(aux.begin(), aux.end());
for(int i = 0; i < aux.size(); i++)
if(i == 0 || aux[i].first != aux[i - 1].first)
aux2.push_back(aux[i].second);
sort(aux2.begin(), aux2.end());
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
precalc();
for(int i = 0; i < t; i++)
{
long long n;
cin >> n;
cout << upper_bound(aux2.begin(), aux2.end(), n) - aux2.begin() << endl;
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
using pt = pair<int, int>;
const int N = 200007;
int n, q;
int k[N];
vector<pt> t[4 * N];
int p[N], e[N], rk[N];
int *pos[3 * N];
int val[3 * N];
int csz;
int ans[N];
void upd(int v, int l, int r, int L, int R, pt val) {
if (L >= R) return;
if (l == L && r == R) {
t[v].push_back(val);
return;
}
int m = (l + r) / 2;
upd(v * 2 + 1, l, m, L, min(R, m), val);
upd(v * 2 + 2, m, r, max(m, L), R, val);
}
void rollback(int tsz) {
while (csz > tsz) {
--csz;
(*pos[csz]) = val[csz];
}
}
pt get(int v) {
if (p[v] == v) return {v, 0};
auto [u, d] = get(p[v]);
return {u, d ^ e[v]};
}
void assign(int& x, int y) {
pos[csz] = &x;
val[csz] = x;
++csz;
x = y;
}
pt unite(int x, int y) {
auto [v, d1] = get(x);
auto [u, d2] = get(y);
if (v == u) return {0, d1 ^ d2};
if (rk[v] > rk[u]) swap(v, u);
assign(p[v], u);
assign(e[v], d1 ^ d2 ^ 1);
assign(rk[u], rk[v] + rk[u]);
return {1, 0};
}
void solve(int v, int l, int r, int cnt) {
int tsz = csz;
for (auto [x, y] : t[v]) {
auto [f, d] = unite(x, y);
//cerr << l << " " << r << " " << x + 1 << " " << y + 1 << " " << f << " " << d << endl;
if (!f) cnt ^= d;
}
if (l != r - 1) {
int m = (l + r) / 2;
solve(v * 2 + 1, l, m, cnt);
solve(v * 2 + 2, m, r, cnt);
} else {
ans[l] = k[l] % 3;
if (ans[l] == 2) ans[l] = cnt + 1;
}
rollback(tsz);
}
int main() {
cin >> n >> q;
vector<int> g(n), lst(n);
for (int i = 0; i < n; ++i) {
cin >> g[i];
--g[i];
}
for (int i = 0; i < q; ++i) {
int x, y;
cin >> x >> y >> k[i];
--x; --y;
upd(0, 0, q, lst[x], i, {x, g[x]});
g[x] = y;
lst[x] = i;
}
for (int i = 0; i < n; ++i) {
upd(0, 0, q, lst[i], q, {i, g[i]});
p[i] = i;
rk[i] = 1;
}
solve(0, 0, q, n & 1);
for (int i = 0; i < q; ++i) {
cout << ans[i] << '\n';
}
}



