#include<bits/stdc++.h> usingnamespace std; using ll = longlong; constint mod = 998244353; constint N = 1e6 + 100; ll a[N]; ll ksm(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) { ans = ans * a % mod; } a = a * a % mod; b >>= 1; } return ans % mod; } voidTotoro() { ll n, s, v; cin >> n >> s >> v; if (s * v >= n) { cout << 1 << "\n"; } else { cout << 0 << '\n'; } }
intmain() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) Totoro(); return0; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong; constint mod = 998244353; constint N = 1e6 + 100; ll ksm(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) { ans = ans * a % mod; } a = a * a % mod; b >>= 1; }
return ans % mod; } voidTotoro() { ll n, m, k; cin >> k; ll sum = 0; vector<ll> a(k + 10); for (int i = 1; i <= k; i++) { cin >> a[i]; } ll x; cin >> n >> m >> x; ll b; b = x % m; for (int i = 1; i <= k; i++) { a[i] %= m; sum += a[i]; } b += (n / k) * sum; ll res = n % k; for (int i = 1; i <= res; i++) { b += a[i]; } cout << n - b / m; }
intmain() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) Totoro(); return0; }
H
image-20240815174756724
我们考虑前缀 max 的位置$ l_1 < l_2 < ... < l_k$,如果在序列
A 选了 \(p_{l_i}\),那 么序列 B
开头的元素一定比\(p_{l_i}\)大,\([l_i,l_i+1)\) 这一段一定在序列 A 中。
那么问题就转化成了一个多重集合 S,是否存在 S 的子集使得子集和为 n/2 。
有一个很重要的性质,多重集合 S 所有数的和是 n,这意味着 S 中本质
不同的数只有 √ n 个。我们对这 √ n 个数做多重背包即可。
#include<bits/stdc++.h> usingnamespace std; using ll = longlong; constint mod = 998244353; constint N = 1e6 + 100; ll ksm(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) { ans = ans * a % mod; } a = a * a % mod; b >>= 1; }
return ans % mod; } voidTotoro() { int n; cin >> n; vector<ll> a(n + 1), pre(n + 1), cnt(n + 1), f(n + 1), bkt(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; pre[i] = max(pre[i - 1], a[i]); } for (int i = 1; i <= n; i++) { ++cnt[pre[i]]; } f[0] = 1; for (int i = 1; i <= n; i++) { if (cnt[i]) { ++bkt[cnt[i]]; } } for (int i = 1; i <= n; i++) { if (bkt[i]) { ll sum = 0; for (int j = 0; sum + (1 << j) <= bkt[i]; ++j) { int v = i * (1 << j); sum += 1 << j; for (int k = n >> 1; k >= v; k--) { f[k] |= f[k - v]; } } if (sum != bkt[i]) { int v = i * (bkt[i] - sum); for (int k = n >> 1; k >= v; k--) { f[k] |= f[k - v]; } } } } if (f[n >> 1]) { cout << "Yes" << '\n'; } else { cout << "No" << '\n'; } }
intmain() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) Totoro(); return0; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong; constint mod = 998244353; constint N = 1e6 + 100; ll f[N]; ll ksm(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) { ans = ans * a % mod; } a = a * a % mod; b >>= 1; }
return ans % mod; } voidTotoro() { int n, k; cin >> n >> k; for (int i = 0; i < n - 1; ++i) { int x, y, z; cin >> x >> y >> z; f[x] ^= z; f[y] ^= z; } while (k--) { int op; cin >> op; if (op == 2) { int x; cin >> x; cout << f[x] << '\n'; } else { int x, y, z; cin >> x >> y >> z; f[x] ^= z, f[y] ^= z; } } }
intmain() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) Totoro(); return0; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong; constint mod = 998244353; constint N = 1e6 + 100; ll ksm(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) { ans = ans * a % mod; } a = a * a % mod; b >>= 1; }
return ans % mod; } voidTotoro() { int n, m; cin >> n; vector<int> th(n + 1); for (int i = 1; i <= n; i++) { cin >> th[i]; } cin >> m; while (m--) { int a, b, x, op; cin >> op; if (op == 1) { cin >> x; int ans = th[x]; double p = sqrt(th[x]); int l = max(1, x - (int)ceil(p)); int r = min(n, x + (int)ceil(p)); for (int i = l; i <= r; i++) { ans = min(ans, th[i] + (x - i) * (x - i)); } cout << ans << '\n'; } else { cin >> a >> b; if (th[a] > b) { th[a] = b; } } } }
intmain() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) Totoro(); return0; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong; constint mod = 998244353; constint N = 1e6 + 100; ll ksm(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) { ans = ans * a % mod; } a = a * a % mod; b >>= 1; }
return ans % mod; } voidTotoro() { int n; cin >> n; vector<ll> a(n + 1), b(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = n - 1; i >= 1; i--) { b[i] = a[i] - a[i + 1]; } sort(b.begin() + 1, b.begin() + n, greater<ll>()); vector<ll> sum(n + 1); for (int i = 1; i <= n - 1; i++) { sum[i] = sum[i - 1] + b[i]; } int m; cin >> m; for (int i = 1; i <= m; i++) { int type; cin >> type; int x; cin >> x; if (type == 0) { continue; } cout << sum[n - 1] - sum[x - 1] << '\n'; } }
intmain() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) Totoro(); return0; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong; constint mod = 998244353; constint N = 1e6 + 100; ll a[N]; ll ksm(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) { ans = ans * a % mod; } a = a * a % mod; b >>= 1; } return ans % mod; } voidTotoro() { int n; cin >> n; cout << n - 1 << '\n'; }
intmain() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) Totoro(); return0; }