func_code_string
stringlengths 59
71.4k
|
---|
#include <bits/stdc++.h> using namespace std; bool check(int a, int b) { bool dig[10] = {0}; while (a > 0) { dig[a % 10] = true; a /= 10; } while (b > 0) { if (dig[b % 10]) { return true; } b /= 10; } return false; } int main() { int a; cin >> a; int i, s = 0; for (i = 1; i * i <= a; i++) { if (a % i == 0) { if (check(a, i)) { s++; } if (i != a / i && check(a, a / i)) { s++; } } } cout << s << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; t = 1; while (t--) { int c = 0; std::vector<int> v; string s[3]; getline(cin, s[0]); getline(cin, s[1]); getline(cin, s[2]); for (int i = 0; i <= 2; i++) { for (int j = 0; j <= s[i].length() - 1; j++) { if (s[i][j] == a || s[i][j] == e || s[i][j] == i || s[i][j] == o || s[i][j] == u ) c++; } v.push_back(c); c = 0; } if (v[0] == 5 && v[1] == 7 && v[2] == 5) { cout << YES ; } else { cout << NO ; } } cerr << Time taken : << (float)clock() / CLOCKS_PER_SEC << secs << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; string s = ; sort(b.rbegin(), b.rend()); if (a.size() > b.size()) s = b.substr(0, a.size()); else s = b; for (int i = 0; i < a.size(); i++) { if (a[i] == 9 ) continue; else if ((a[i] + 0 ) < (s[0] + 0 )) { a[i] = s[0]; s.erase(0, 1); } } cout << a << endl; }
|
#include <bits/stdc++.h> using namespace std; int main() { string s, ans = ; cin >> s; int i = 0, j = s.size() - 1; while (i < j) { if (s[i] == s[j]) { i++; j--; continue; } else { s.insert(s.begin() + j + 1, s[i]); i++; } } cout << s << endl; }
|
#include <bits/stdc++.h> using namespace std; int main() { int n, flag; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; if (n == 2) cout << a[0] + 2 * (a[1] - a[0]); else { for (int i = 0; i < n - 2; i++) { if ((a[i + 2] - a[i + 1]) != (a[1 + i] - a[i])) { flag = 0; break; } else flag = 1; } if (flag) { cout << a[0] + (n) * (a[1] - a[0]); } else cout << a[n - 1]; } }
|
#include <bits/stdc++.h> using namespace std; void Read(int &p) { p = 0; char c = getchar(); for (; c < 0 || c > 9 ; c = getchar()) ; for (; c >= 0 && c <= 9 ; c = getchar()) p = p * 10 + c - 0 ; } struct ma { int x, y; ma(int _x = 0, int _y = 0) : x(_x), y(_y) {} }; bool operator<(ma a, ma b) { return a.x < b.x; } priority_queue<ma> q[100005], Q, _q; int n, m, x, y, z, rot, mi = 1e9, si[100005], nm = 0, be[100005]; int fir[100005], tar[200005], len[200005], nex[200005], cnt; long long ans1; void Add(int a, int b, int c) { ++cnt; tar[cnt] = b; len[cnt] = c; nex[cnt] = fir[a]; fir[a] = cnt; } int Dfs(int r, int fa) { int sz = 1, mx = 0; for (int i = fir[r]; i; i = nex[i]) { int v = tar[i]; if (v != fa) { int sum = Dfs(v, r); mx = max(mx, sum); sz += sum; ans1 += (long long)len[i] * min(sum, n - sum); } } mx = max(mx, n - sz); if (mx < mi) rot = r, mi = mx; return sz; } void DFS(int x, int fa, int d) { q[d].push(ma{-x, d}); si[d]++; be[x] = d; for (int i = fir[x]; i; i = nex[i]) if (tar[i] != fa) DFS(tar[i], x, d); } int work(int u) { while (_q.top().x != q[_q.top().y].top().x || q[_q.top().y].empty()) _q.pop(); ma o; if (_q.top().y == u) o = _q.top(), _q.pop(); while (_q.top().x != q[_q.top().y].top().x || q[_q.top().y].empty()) _q.pop(); u = _q.top().y; if (o.x) _q.push(o); return u; } int main() { Read(n); if (n == 1) { printf( 0 n1 n ); return 0; } for (int i = 1; i < n; i++) { int u, v, w; Read(u), Read(v), Read(w); Add(u, v, w), Add(v, u, w); } Dfs(1, 0); q[0].push(ma{-rot, 0}); _q.push(ma{-rot, 0}); si[0] = 1; for (int i = fir[rot]; i; i = nex[i]) { DFS(tar[i], rot, ++nm); Q.push(ma{si[nm] << 1, nm}); _q.push(ma(q[nm].top().x, nm)); } printf( %lld n , ans1 << 1); for (int i = 1; i <= n; i++) { while (Q.top().x != si[Q.top().y] + q[Q.top().y].size()) Q.pop(); if (be[i] == Q.top().y || Q.top().x < n - i + 1) m = work(be[i]); else m = Q.top().y; if (i == rot && -q[m].top().x > rot && !q[0].empty() && Q.top().x < n - i + 1) m = 0; printf( %d , -q[m].top().x); q[m].pop(); si[be[i]]--; if (!q[m].empty()) _q.push(ma(q[m].top().x, m)); Q.push(ma(si[m] + q[m].size(), m)); Q.push(ma(si[be[i]] + q[be[i]].size(), be[i])); } }
|
#include <bits/stdc++.h> using namespace std; long long expo(long long base, long long exponent, long long mod) { long long ans = 1; while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base) % mod; base = (1LL * base * base) % mod; exponent >>= 1; } return ans % mod; } const long long mod = 998244353; const long long root = 565042129; const long long root_1 = 950391366; const long long root_pw = 1 << 20; void fft(vector<long long> &a, bool invert) { long long i, j, n = (long long)a.size(); for (i = 1, j = 0; i < n; ++i) { long long bit = n >> 1; for (; j >= bit; bit >>= 1) { j -= bit; } j += bit; if (i < j) swap(a[i], a[j]); } for (long long len = 2; len <= n; len <<= 1) { long long wlen = invert ? root_1 : root; for (i = len; i < root_pw; i <<= 1) { wlen = (wlen * wlen % 998244353); } for (i = 0; i < n; i += len) { long long w = 1; for (j = 0; j < len / 2; ++j) { long long u = a[i + j], v = (long long)(a[i + j + len / 2] * w % 998244353); a[i + j] = (u + v + 998244353) % 998244353; a[i + j + len / 2] = (u - v + 998244353) % 998244353; w = (w * wlen % 998244353); } } } if (invert) { long long nrev = expo(n, 998244353 - 2, 998244353); for (i = 0; i < n; ++i) { a[i] = (a[i] * nrev % 998244353); } } } void multiply(const vector<long long> &a, const vector<long long> &b, vector<long long> &res) { vector<long long> fa(a.begin(), a.end()), fb(b.begin(), b.end()); size_t n = 1; while (n < max(a.size(), b.size())) n <<= 1; n <<= 1; fa.resize(n), fb.resize(n); fft(fa, false), fft(fb, false); for (size_t i = 0; i < n; ++i) { fa[i] *= fb[i]; } fft(fa, true); res.resize(n); for (size_t i = 0; i < n; ++i) { res[i] = fa[i]; } } vector<long long> ans; signed main() { long long n, first, k; vector<long long> pol(1001, 0); vector<long long> ans(1, 1); cin >> n >> k; vector<long long> temp; for (long long i = 0; i < (long long)n; i++) { cin >> first; pol[first] = 1; } while (k) { if (k % 2) { multiply(ans, pol, ans); for (long long i = 0; i < (long long)ans.size(); i++) { if (ans[i]) ans[i] = 1; else ans[i] = 0; } } multiply(pol, pol, pol); for (long long i = 0; i < (long long)pol.size(); i++) { if (pol[i]) pol[i] = 1; else pol[i] = 0; } k /= 2; } for (long long i = 0; i < (long long)ans.size(); i++) { if (ans[i]) cout << i << ; } }
|
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0; cin >> n; int arr[n]; set<int> s; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); for (int i = 1; i < n; i++) { if (arr[i] == arr[i - 1]) { c++; arr[i]++; } else if (arr[i] < arr[i - 1]) { while (arr[i] <= arr[i - 1]) { arr[i]++; c++; } } } cout << c; }
|
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, s = 0; cin >> a >> b; while (b > 1) { if (b > a) swap(a, b); s += a / b; a -= (b * (a / b)); if (a < 1) break; } s += a; cout << s << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; long long int mod_Expo(long long int x, long long int n, long long int M) { if (x == 0) return 0; if (n == 0) return 1; else if (n % 2 == 0) return mod_Expo((x * x) % M, n / 2, M); else return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M; } long long int binaryExponentiation(long long int x, long long int n) { if (x == 0) return 0; if (n == 0) return 1; else if (n % 2 == 0) return binaryExponentiation(x * x, n / 2); else return x * binaryExponentiation(x * x, (n - 1) / 2); } long long int GCD(long long int A, long long int B) { if (B == 0) return A; else return GCD(B, A % B); } bool prime_check(long long int x) { bool prime = (x >= 2); for (long long i = 2; i * i <= x; i++) { if (x % i == 0) { prime = false; break; } } return prime; } long long int min1(long long int a, long long int b, long long int c) { vector<long long int> v1, v2, v3; v1.push_back(b); v1.push_back(c); v1.push_back(a); sort(v1.begin(), v1.end()); return v1[0]; } long long int min(long long int a, long long int b) { if (a <= b) return a; else return b; } long long int bin_search(long long int x, long long int low, long long int high, vector<long long int> v1) { while (high > low) { long long int mid = low + (high - low) / 2; if (v1[mid] > x) high = mid; else low = mid + 1; } return high; } long long int digitsum(long long int n) { long long int sum = 0; while (n != 0) { sum = sum + n % 10; n = n / 10; } return sum; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, i, j, t, f = 0, g = 0, x, y, z, k, a = 0, b = 0, c = 0, q, x1, x2, y1, y2, x3, max2, min1 = 1000000, x4, sum, d, M = 998244353, r, p, sum1 = 0, sum2 = 0, sum3 = 0, sum4, sum5, max1 = 0, sum6; cin >> t; while (t--) { cin >> n; long long int arr[n], arr1[n]; f = 0; set<long long int> s; for (i = 0; i < n; i++) { cin >> arr[i]; s.insert(arr[i]); arr1[i] = arr[i]; } sort(arr1, arr1 + n); for (i = n - 1; i >= 0; i--) { if (arr1[i] == arr[n - 1 - i]) { f++; } } if (f == n) { if (s.size() < n) cout << YES << endl; else cout << NO << endl; } else cout << YES << endl; } }
|
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; cin >> n; int a[n][2], maxi = -100; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j <= 0; j++) { sum = sum - a[i][j]; sum = sum + a[i][j + 1]; maxi = max(maxi, sum); } } cout << maxi; }
|
#include <bits/stdc++.h> using namespace std; const long long int maxN = 2e5 + 100; const long long int maxM = 1e3 + 100; const long long int mod = 1e9 + 7; const long long int hmod = 1e16 + 7; const long double PI = 3.141592653; const long double eps = 1e-8; const long long int D = 1379; const long long int INF = 1e18 + 20; const long long int Inf = 1e9 + 140; long long int dp1[maxN]; long long int dp2[maxN]; long long int n, a[maxN]; long long int sum[maxN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (long long int i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] + a[i]; dp1[n] = sum[n]; dp2[n] = -dp1[n]; for (long long int i = n - 1; i >= 1; i--) { dp1[i] = max(dp1[i + 1], dp2[i + 1] + sum[i]); dp2[i] = -dp1[i]; } cout << dp1[2] << endl; }
|
#include <bits/stdc++.h> using namespace std; string s; long long heavy; long long ukupno; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> s; heavy = 0; ukupno = 0; for (int i = 4; i < s.size(); i++) { if (s[i] == l && s[i - 1] == a && s[i - 2] == t && s[i - 3] == e && s[i - 4] == m ) ukupno += heavy; else if (s[i] == y && s[i - 1] == v && s[i - 2] == a && s[i - 3] == e && s[i - 4] == h ) heavy++; } cout << ukupno; return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int n, a[93], b[93]; scanf( %d , &n); int ans = 0; a[0] = 0; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); b[i - 1] = a[i] - a[i - 1]; } b[n] = 90 - a[n]; for (int i = 0; i <= n; i++) { if (b[i] > 15) { ans = a[i] + 15; break; } } if (!ans) ans = 90; printf( %d n , ans); return 0; }
|
#include <bits/stdc++.h> using namespace std; const long long INF = 0x1fffffffffffffff; const double INFD = 1e20; const double EPS = 1e-9; const double PI = atan(1) * 4; const long long M = 998244353; long long mod(long long x) { return ((x % M) + M) % M; } long long add(long long a, long long b) { return mod(mod(a) + mod(b)); } long long sub(long long a, long long b) { return mod(mod(a) - mod(b)); } long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); } long long power(long long b, long long e) { long long ans = 1; while (e > 0) { if (e % 2) ans = mul(ans, b); b = mul(b, b); e /= 2; } return mod(ans); } long long gcd(long long a, long long b) { for (; b > 0; swap(a, b)) a %= b; return a; } long long extended_euclid(long long a, long long b, long long &x, long long &y) { long long xx = y = 0; long long yy = x = 1; while (b) { long long q = a / b; long long t = b; b = a % b; a = t; t = xx; xx = x - q * xx; x = t; t = yy; yy = y - q * yy; y = t; } return a; } long long inv(long long a) { long long x, y; long long d = extended_euclid(a, M, x, y); if (d > 1) return -1; return mod(x); } long long scan() { long long r; scanf( %lld , &r); return r; } void scanstr(char *buf) { scanf( %s , buf); } int main() { long long n = scan(); vector<long long> a(n); for (long long i = 0; i < n; ++i) { a[i] = scan(); } sort(a.begin(), a.end()); vector<long long> pfs(n + 1, 0); for (long long i = 0; i < n; ++i) pfs[i + 1] = add(pfs[i], a[i]); long long q_inv = inv(n); for (long long i = 1; i < n; ++i) { long long segcount = (i <= n / 2) ? i : (n - i); long long ballcount = n - i; long long q = ballcount / segcount; long long r = ballcount % segcount; long long ans = mul(q + 1, pfs[r]); for (long long j = 1; j < q + 1; ++j) { long long cur = mul( q + 1 - j, sub(pfs[r + segcount * j], pfs[r + segcount * (j - 1)])); ans = add(ans, cur); } cout << mul(ans, q_inv) << endl; } cout << 0 << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; vector<long long> adj[200005]; long long siz = 0; long long cc = 0; long long t, n; long long a[200005]; long long vis[200005]; long long size_dict[200005]; void dfs(long long u) { vis[u] = cc; siz += 1; for (long long i = 0; i < adj[u].size(); i++) { if (!vis[adj[u][i]]) { dfs(adj[u][i]); } } } int main() { cin >> t; while (t--) { cin >> n; for (long long i = 0; i <= 200004; i++) { adj[i].clear(); } for (long long i = 0; i <= 200004; i++) vis[i] = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; adj[i + 1].push_back(a[i]); adj[a[i]].push_back(i + 1); } cc = 0; for (long long i = 0; i < n; i++) { if (!vis[i + 1]) { cc++; dfs(i + 1); size_dict[cc] = siz; siz = 0; } } for (long long i = 1; i <= n; i++) { cout << size_dict[vis[i]] << ; } cout << n ; } }
|
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, x1, y1, x2, y2, left, right; cin >> a >> b >> x1 >> y1 >> x2 >> y2; int r1 = (x2 - y2) / (2 * b); int r2 = (x1 - y1) / (2 * b); int r3 = (x2 + y2) / (2 * a); int r4 = (x1 + y1) / (2 * a); left = ((x2 - y2) / (2 * b) - (x1 - y1) / (2 * b)); right = ((x2 + y2) / (2 * a) - (x1 + y1) / (2 * a)); if (x2 - y2 < 0) left -= 1; if (x1 - y1 < 0) left += 1; if (x2 + y2 < 0) right -= 1; if (x1 + y1 < 0) right += 1; cout << max(abs(left), abs(right)); return 0; }
|
#include <bits/stdc++.h> using namespace std; int n_keys, n_chests; int odd_keys, even_keys, odd_chests, even_chests; int main() { cin >> n_keys >> n_chests; for (int i = 0; i < n_keys; i++) { int x; cin >> x; if (x % 2 == 0) even_keys++; else odd_keys++; } for (int i = 0; i < n_chests; i++) { int x; cin >> x; if (x % 2 == 0) even_chests++; else odd_chests++; } cout << min(even_chests, odd_keys) + min(odd_chests, even_keys) << n ; }
|
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2) { cout << contest n ; } else { cout << home n ; } }
|
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); if (v[0] == v[n / 2]) { cout << Bob << endl; } else { cout << Alice << endl; } }
|
#include <bits/stdc++.h> int main() { int n, a[102], sum1 = 0, sum2 = 0; int s, t; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); scanf( %d %d , &s, &t); if (s == t) { printf( 0 n ); } else { int i; if (s > t) { s ^= t; t ^= s; s ^= t; } for (i = s - 1; i < t - 1; i++) sum1 += a[i]; for (i = t - 1; i < n; i++) sum2 += a[i]; for (i = 0; i < s - 1; i++) sum2 += a[i]; int ans; sum1 > sum2 ? (ans = sum2) : (ans = sum1); printf( %d n , ans); } return 0; }
|
#include <bits/stdc++.h> using namespace std; const int Maxn = 3e6 + 10, Maxk = 1e6 + 10; int a[Maxn], l[Maxn], r[Maxn], s[Maxn], n, k; vector<int> v[Maxk]; long long ans; int ask(int k, int l, int r) { int x = upper_bound(v[k].begin(), v[k].end(), r) - v[k].begin() - 1, y = lower_bound(v[k].begin(), v[k].end(), l) - v[k].begin() - 1; return x - y; } int main() { ios::sync_with_stdio(0); int i, j; cin >> n >> k; for (i = 1; i <= n; i++) cin >> a[i], s[i] = (s[i - 1] + a[i]) % k; for (i = 0; i <= n; i++) v[s[i]].push_back(i); for (i = 1; i <= n; i++) for (l[i] = i - 1; l[i] >= 1 && a[l[i]] < a[i]; l[i] = l[l[i]]) ; for (i = n; i >= 1; i--) for (r[i] = i + 1; r[i] <= n && a[r[i]] <= a[i]; r[i] = r[r[i]]) ; for (i = 1; i <= n; i++) if (i - l[i] < r[i] - i) { for (j = l[i] + 1; j <= i; j++) ans += ask((a[i] + s[j - 1]) % k, i, r[i] - 1); } else { for (j = i; j <= r[i] - 1; j++) ans += ask(((s[j] - a[i]) % k + k) % k, l[i], i - 1); } cout << ans - n << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int T; scanf( %d , &T); while (T--) { int n, ans = 0; scanf( %d , &n); map<string, int> book; vector<string> aa, temp; for (int i = 1; i <= n; i++) { string s; cin >> s; book[s] = 1; temp.push_back(s); } for (vector<string>::iterator it = temp.begin(); it < temp.end(); it++) { string s; s = *it; if (book[s] == 1) { book[s]++; aa.push_back(s); } else { for (int i = 0; i <= 9; i++) { s[3] = i + 0 ; if (!book.count(s)) { book[s] = 1; aa.push_back(s); break; } } ans++; } } printf( %d n , ans); for (vector<string>::iterator it = aa.begin(); it < aa.end(); it++) cout << *it << endl; } }
|
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; while (t--) { long long l, r, i, sum = 0; deque<long long> a; a.push_back(4); a.push_back(7); cin >> l >> r; for (i = l; i <= r;) { if (i <= a.front()) { sum += a.front(); i++; } else { a.push_back(a.front() * 10 + 4); a.push_back(a.front() * 10 + 7); a.pop_front(); } } cout << sum << ; } return 0; }
|
#include <bits/stdc++.h> const double PI = 3.1415926535897932384626433; const int KL = 1e6; using namespace std; const long long MOD = 998244353; int mul(int x, int y) { return x * 1LL * y % MOD; } int add(int x, int y) { x += y; if (x >= MOD) x -= MOD; return x; } int sub(int x, int y) { x -= y; if (x < 0) x += MOD; return x; } int pow(int u, int v) { if (v == 0) return 1; int ret = pow(u, v / 2); ret = mul(ret, ret); if (v % 2 == 1) ret = mul(ret, u); return ret; } int fact[KL + 10], invi[KL + 10], inv[KL + 10]; void init() { fact[0] = invi[0] = invi[1] = inv[0] = 1; for (int i = 1; i < KL; i++) fact[i] = mul(fact[i], i); for (int i = 2; i < KL; i++) invi[i] = mul(invi[MOD % i], MOD - MOD / i); for (int i = 1; i < KL; i++) inv[i] = mul(inv[i - 1], invi[i]); } int C(int u, int v) { if (u < v) return 0; return mul(fact[u], mul(inv[v], inv[u - v])); } int k, A, h, pw[KL], place[KL]; vector<pair<int, int>> res[2][2]; void solve(int mask, int pos) { vector<int> vec; if (pos == 0) for (int i = 1; i <= pw[k - 1]; i++) vec.push_back(i); else for (int i = pw[k - 1] + 1; i <= pw[k]; i++) vec.push_back(i); int ret = 0, cnt = 0; while (1) { if (vec.size() == 1) { place[vec[0]] = 2; int ad = mul(A, vec[0]); res[pos][0].push_back({add(ad, ret), mask}); ad = mul(ad, A); res[pos][1].push_back({add(ad, ret), mask}); break; } vector<int> nw; for (int j = 1; j < vec.size(); j += 2) { if ((mask & pw[cnt])) { nw.push_back(vec[j - 1]); int ad = mul(vec[j], pow(A, (int)vec.size() + 1)); ret = add(ret, ad); place[vec[j]] = vec.size() + 1; } else { nw.push_back(vec[j]); int ad = mul(vec[j - 1], pow(A, (int)vec.size() + 1)); ret = add(ret, ad); place[vec[j - 1]] = vec.size() + 1; } cnt++; } vec.clear(); for (auto v : nw) vec.push_back(v); } } map<int, int> mp; bool fnd(int i, int j) { mp.clear(); int pos = 1; for (auto v : res[0][i]) { mp[v.first] = pos; pos++; } int pos1 = 0, pos2 = 1; for (auto v : res[1][j]) { int rem = sub(h, v.first); pos1 = mp[rem]; if (pos1 > 0) break; pos2++; } if (pos1 == 0) return false; int mask1 = res[0][i][pos1 - 1].second; int mask2 = res[1][j][pos2 - 1].second; solve(mask1, 0); solve(mask2, 1); if (i == 0) { for (int id = 1; id <= pw[k - 1]; id++) if (place[id] == 2) place[id] = 1; } else { for (int id = pw[k - 1] + 1; id <= pw[k]; id++) if (place[id] == 2) place[id] = 1; } for (int id = 1; id <= pw[k]; id++) printf( %d , place[id]); printf( n ); return 1; } int main() { pw[0] = 1; for (int i = 1; i <= 17; i++) pw[i] = mul(pw[i - 1], 2); scanf( %d , &k); scanf( %d , &A); scanf( %d , &h); for (int mask = 0; mask < pw[pw[k - 1]]; mask++) { solve(mask, 0); solve(mask, 1); } if (fnd(1, 0)) return 0; if (fnd(0, 1)) return 0; puts( -1 ); return 0; }
|
#include <bits/stdc++.h> using namespace std; int typetest; inline void fastIOfileinput() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); typetest = 1; } const int N = 1e2 + 2; long long n; void Enter() { cin >> n; } long long cnt() { return (long long)((long long)sqrt((long double)(24 * n + 1)) - 7) / 6; } void solve() { long long ans = 0, x; while (n > 1) { ++ans; x = cnt(); n -= (x + 1) * (3 * x + 4) / 2; } cout << ans << n ; } int main() { fastIOfileinput(); if (typetest) { int t; cin >> t; while (t--) { Enter(); solve(); } } else { Enter(); solve(); } }
|
#include <bits/stdc++.h> int main() { float a, b, x, y, v, g, k = 10000.000; int i, n; scanf( %f %f %d , &a, &b, &n); for (i = 0; i < n; i++) { scanf( %f %f %f , &x, &y, &v); g = (x - a) * (x - a) + (y - b) * (y - b); g = sqrt(g); g = g / v; if (g < k) { k = g; } } printf( %f n , k); return 0; }
|
#include <bits/stdc++.h> using namespace std; template <typename T> inline string toString(T a) { ostringstream os( ); os << a; return os.str(); } template <typename T> inline long long toLong(T a) { long long res; istringstream os(a); os >> res; return res; } template <typename T> inline int toInt(T a) { int res; istringstream os(a); os >> res; return res; } template <typename T> inline double toDouble(T a) { double res; istringstream os(a); os >> res; return res; } template <typename T> inline T SQ(T a) { return a * a; } template <typename T> inline T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); } template <typename T> inline T LCM(T a, T b) { long long res = a * b; res /= GCD(a, b); return res; } template <typename T> inline unsigned long long BIGMOD(T a, T b, T m) { if (b == 0) return 1; else if (b % 2 == 0) return SQ(BIGMOD(a, b / 2, m)) % m; else return (a % m * BIGMOD(a, b - 1, m)) % m; } template <typename T> inline vector<string> PARSE(T str) { vector<string> res; string s; istringstream os(str); while (os >> s) res.push_back(s); return res; } template <typename T> inline unsigned long long DIST(T A, T B) { unsigned long long res = (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y); return res; } template <typename T> inline long long CROSS(T A, T B, T C) { return (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y); } template <typename T> inline double cosAngle(T a, T b, T c) { double res = a * a + b * b - c * c; res = res / (2 * a * b); res = acos(res); return res; } template <typename T> inline T POWER(T base, int po) { T res = 1; if (base == 0) return 0; for (int i = (0); i < (po); i++) res *= base; return res; } template <typename T> inline bool IS_ON(T mask, T pos) { return mask & (1 << pos); } template <typename T> inline int OFF(T mask, T pos) { return mask ^ (1 << pos); } template <typename T> inline int ON(T mask, T pos) { return mask | (1 << pos); } template <typename T> inline bool INSIDE_GRID(int R, int C, int ro, int clm) { if (R >= 0 && C >= 0 && R < ro && C < clm) return 1; return 0; } template <typename T> inline void PRINT_GRID(T GRID, int ro, int clm) { cout << GRID << : << GRID << endl; for (int i = (0); i < (ro); i++) { for (int j = (0); j < (clm); j++) cout << GRID[i][j] << ; puts( ); } } map<string, int> mp; pair<long long, long long> dp[800005]; vector<int> g[800005]; vector<int> gr[800005]; int stk[800008]; string str, str2; vector<string> inp; pair<long long, long long> Tolower(string &str) { int len = str.size(), r = 0; for (int i = (0); i < (len); i++) { str[i] = tolower(str[i]); if (str[i] == r ) r++; } return make_pair((long long)r, (long long)len); } int vis[800005], top = 0, rng; void trop(int u) { vis[u] = 1; for (int i = (g[u].size() - 1); i >= (0); i--) if (!vis[g[u][i]]) trop(g[u][i]); stk[++top] = u; } void manipul(int u, int papa) { vis[u] = 3; dp[u] = min(dp[u], dp[papa]); for (int i = (gr[u].size() - 1); i >= (0); i--) if (vis[gr[u][i]] != 3) manipul(gr[u][i], papa); } pair<long long, long long> DP(int pos) { if (vis[pos] != 2) { vis[pos] = 2; for (int i = (g[pos].size() - 1); i >= (0); i--) dp[pos] = min(dp[pos], DP(g[pos][i])); } return dp[pos]; } int main() { int n, m; int cnt = 1; int s, d, len, r; for (int i = (0); i < (800000); i++) dp[i] = make_pair(100000000000000LL, 100000000000000LL); scanf( %d , &n); pair<long long, long long> tmp; for (int i = (0); i < (n); i++) { cin >> str; tmp = Tolower(str); inp.push_back(str); if (mp.find(str) == mp.end()) mp[str] = cnt++; s = mp[str]; dp[s] = min(dp[s], tmp); } rng = cnt; scanf( %d , &m); for (int i = (0); i < (m); i++) { cin >> str >> str2; tmp = Tolower(str); tmp = Tolower(str2); if (mp.find(str) == mp.end()) mp[str] = cnt++; if (mp.find(str2) == mp.end()) mp[str2] = cnt++; s = mp[str]; d = mp[str2]; dp[d] = min(dp[d], tmp); dp[s] = min(dp[s], dp[d]); g[s].push_back(d); gr[d].push_back(s); } pair<long long, long long> res; res = make_pair(0, 0); for (int i = (0); i < (n); i++) { s = mp[inp[i]]; if (!vis[s]) trop(s); } for (int i = (top + 1 - 1); i >= (0); i--) { DP(stk[i]); } for (int i = (top + 1 - 1); i >= (0); i--) { if (vis[stk[i]] != 3) manipul(stk[i], stk[i]); } for (int i = (0); i < (n); i++) { s = mp[inp[i]]; res.first += dp[s].first; res.second += dp[s].second; } cout << res.first << << res.second << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) #pragma GCC optimize( unroll-loops ) const long long int mod = 1e9 + 7; const long long int mod1 = 998244353; const long long int inf = 1e18; const long long int MX = 1e6 + 1; const double PI = 3.141592653589793238; template <typename T> ostream& operator<<(ostream& out, const vector<T>& v) { out << [ ; for (auto i = v.begin(); i != v.end(); i++) out << (i != v.begin() ? , : ) << (*i); return (out << ] ); } template <typename T> ostream& operator<<(ostream& out, const set<T>& s) { out << [ ; for (auto i = s.begin(); i != s.end(); i++) out << (i != s.begin() ? , : ) << (*i); return (out << ] ); } template <typename T> ostream& operator<<(ostream& out, const unordered_set<T>& s) { out << n << [ ; for (auto i = s.begin(); i != s.end(); i++) out << (i != s.begin() ? , : ) << (*i); return (out << ] ); } template <typename T1, typename T2> ostream& operator<<(ostream& out, const pair<T1, T2>& p) { return (out << ( << p.first << , << p.second << ) ); } template <typename T1, typename T2> ostream& operator<<(ostream& out, const map<T1, T2>& m) { out << { << n ; for (auto x : m) out << << x.first << -> << x.second << n ; return (out << } ); } template <typename T1, typename T2> ostream& operator<<(ostream& out, const unordered_map<T1, T2>& m) { out << { << n ; for (auto x : m) out << << x.first << -> << x.second << n ; return (out << } ); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; cin.ignore(); while (t--) { long long int n, m; cin >> n >> m; map<long long int, long long int> mp; for (long long int i = 0; i < m; i++) { long long int x, y, z; cin >> x >> y >> z; mp[y]++; } long long int p1 = 0; for (long long int i = 0; i < n; i++) { if (mp.find(i + 1) == mp.end()) { p1 = i + 1; break; } } for (long long int i = 0; i < n; i++) { if (i + 1 == p1) { continue; } cout << p1 << << i + 1 << n ; } } }
|
#include <bits/stdc++.h> using namespace std; void Solve() { int n; string a, b; cin >> n >> a >> b; a = - + a + - ; b = - + b + - ; int val = 0; for (int i = 1; i <= n; i++) { if (a[i] != b[i]) val += 2; else if (a[i] == 0 ) { val++; if (a[i - 1] == 1 && b[i - 1] == 1 ) val++; else if (a[i + 1] == 1 && b[i + 1] == 1 ) { val++; a[i + 1] = b[i + 1] = - ; } } } cout << val << endl; } int main() { int t; cin >> t; while (t--) Solve(); return 0; }
|
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; bool f = 1; char s = getchar(); while ((s < 0 || s > 9 ) && s > 0) { if (s == - ) f ^= 1; s = getchar(); } while (s >= 0 && s <= 9 ) x = (x << 1) + (x << 3) + s - 0 , s = getchar(); return f ? x : -x; } int n, m, ans[500005]; int IN, dfn[500005], low[500005], bl[500005], tot; stack<int> st; int d1[500005], sd[500005], d2[500005], ccg[500005]; vector<int> G[500005], cl[500005]; inline void dfs0(int x, int fa) { dfn[x] = low[x] = ++IN, st.push(x); for (unsigned i = 0; i < G[x].size(); i++) { int v = G[x][i]; if (v == fa) continue; if (!dfn[v]) dfs0(v, x), low[x] = min(low[x], low[v]); else low[x] = min(low[x], dfn[v]); } if (low[x] == dfn[x]) { tot++; while (!st.empty() && dfn[st.top()] >= dfn[x]) bl[st.top()] = tot, cl[tot].push_back(st.top()), st.pop(); } } queue<int> q; int db[500005]; inline void bfs1(int x) { for (int i = 1; i <= n; i++) db[i] = -1; db[x] = 0, q.push(x); while (!q.empty()) { int u = q.front(); q.pop(); for (unsigned i = 0; i < G[u].size(); i++) { int v = G[u][i]; if (db[v] < 0) db[v] = db[u] + 1, q.push(v); } } } inline void dfs1(int x) { d1[x] = 1; for (unsigned i = 0; i < G[x].size(); i++) { int v = G[x][i]; if (db[v] == db[x] + 1) { if (!d1[v]) dfs1(v); d1[x] = max(d1[x], d1[v] + 1); } } } struct node { int x, y; node() {} node(int X, int Y) { x = X, y = Y; } }; int dq[500005 << 1], hd, tl; bool vis[500005]; inline void dfs2(int x) { vis[x] = 1; int len = cl[x].size(), cj = len >> 1; for (int id = 0; id < len; id++) { int u = cl[x][id]; sd[u] = ans[u] = 1; for (unsigned i = 0; i < G[u].size(); i++) { int v = G[u][i]; if (bl[u] != bl[v]) sd[u] = max(sd[u], d1[v] + 1); } } hd = tl = 0; for (int i = cj, lim = len << 1; i < lim; i++) { int u = cl[x][i % len], p; while (hd < tl && i - dq[hd] > cj) hd++; if (hd < tl) p = dq[hd], ans[u] = max(ans[u], i - p + sd[cl[x][p % len]]); while (hd < tl && ((p = dq[tl - 1]) || 1) && i - p + sd[cl[x][p % len]] < sd[u]) tl--; dq[tl++] = i; } hd = tl = 0; for (int i = cj, g = (len << 1) - 1; i <= g; i++) { int u = cl[x][(g - i) % len], p; while (hd < tl && i - dq[hd] > cj) hd++; if (hd < tl) p = dq[hd], ans[u] = max(ans[u], i - p + sd[cl[x][(g - p) % len]]); while (hd < tl && ((p = dq[tl - 1]) || 1) && i - p + sd[cl[x][(g - p) % len]] < sd[u]) tl--; dq[tl++] = i; } for (int id = 0; id < len; id++) { int u = cl[x][id]; hd = tl = 0; for (unsigned i = 0; i < G[u].size(); i++) if (bl[G[u][i]] != x) { int v = G[u][i]; while (hd < tl && d1[dq[tl - 1]] < d1[v]) tl--; dq[tl++] = v; } for (unsigned i = 0; i < G[u].size(); i++) if (bl[G[u][i]] != x) { int v = G[u][i], cg = ans[u]; if (hd < tl && dq[hd] == v) hd++; if (hd < tl) cg = max(cg, d1[dq[hd]] + 1); while (hd < tl && d1[dq[tl - 1]] < d1[v]) tl--; dq[tl++] = v; if (!vis[bl[v]]) ccg[v] = cg; } for (unsigned i = 0; i < G[u].size(); i++) if (bl[G[u][i]] != x) { int v = G[u][i]; if (!vis[bl[v]]) swap(d1[u], ccg[v]), dfs2(bl[v]), swap(d1[u], ccg[v]); } } } signed main() { n = read(), m = read(); for (int i = 1; i <= m; i++) { int u = read(), v = read(); G[u].push_back(v), G[v].push_back(u); } dfs0(1, 0); bfs1(1), dfs1(1); dfs2(bl[1]); for (int i = 1; i <= n; i++) printf( %d , max(ans[i], sd[i]) - 1); return 0; }
|
#include <bits/stdc++.h> using namespace std; int Read() { char c; while (c = getchar(), (c != - ) && (c < 0 || c > 9 )) ; bool neg = (c == - ); int ret = (neg ? 0 : c - 48); while (c = getchar(), c >= 0 && c <= 9 ) ret = ret * 10 + c - 48; return neg ? -ret : ret; } const int MAXN = 300005; const long double eps = 1e-10; struct node { long double l, r, a, b, c, dx, da, db, dc; int fa, son[2]; long double F(long double x) { return (a * x + b) * x + c; } } t[MAXN << 1]; int N, Q, A, B, root, cnt; long double ans[MAXN], apex[MAXN]; inline int CreateNew(long double l, long double r, long double a = 0, long double b = 0, long double c = 0, int c0 = 0, int c1 = 0) { return t[++cnt].l = l, t[cnt].r = r, t[cnt].a = a, t[cnt].b = b, t[cnt].c = c, t[cnt].son[0] = c0, t[cnt].son[1] = c1, cnt; } inline void MarkX(int x, long double dx) { t[x].c += (t[x].a * dx - t[x].b) * dx; t[x].dc += (t[x].da * dx - t[x].db) * dx; t[x].b += -2 * t[x].a * dx, t[x].db += -2 * t[x].da * dx; t[x].l += dx, t[x].r += dx, t[x].dx += dx; } inline void MarkY(int x, long double da, long double db, long double dc) { t[x].a += da, t[x].b += db, t[x].c += dc; t[x].da += da, t[x].db += db, t[x].dc += dc; } inline void Pushdown(int x) { if (t[x].son[0]) MarkX(t[x].son[0], t[x].dx), MarkY(t[x].son[0], t[x].da, t[x].db, t[x].dc); if (t[x].son[1]) MarkX(t[x].son[1], t[x].dx), MarkY(t[x].son[1], t[x].da, t[x].db, t[x].dc); t[x].dx = t[x].da = t[x].db = t[x].dc = 0; } inline void Rotate(int x, int tp) { int y = t[x].fa; Pushdown(y), Pushdown(x); t[y].son[!tp] = t[x].son[tp]; t[x].fa = t[y].fa; if (t[x].son[tp]) t[t[x].son[tp]].fa = y; if (t[y].fa) t[t[y].fa].son[t[t[y].fa].son[1] == y] = x; else root = x; t[y].fa = x, t[x].son[tp] = y; } inline void Splay(int x) { for (Pushdown(x); t[x].fa;) if (t[x].fa == root) Rotate(x, t[t[x].fa].son[0] == x); else { int y = t[x].fa, z = t[y].fa; if (y == t[z].son[0]) if (x == t[y].son[0]) Rotate(y, 1), Rotate(x, 1); else Rotate(x, 0), Rotate(x, 1); else if (x == t[y].son[1]) Rotate(y, 0), Rotate(x, 0); else Rotate(x, 1), Rotate(x, 0); } } inline long double FindOpt(int x) { for (;;) { Pushdown(x); long double opt = min(-t[x].b * 0.5 / t[x].a, (long double)Q); if (opt < t[x].l - eps) if (t[x].son[0]) x = t[x].son[0]; else return Splay(x), t[x].l; else if (opt > t[x].r + eps) if (t[x].son[1]) x = t[x].son[1]; else return Splay(x), t[x].r; else return Splay(x), opt; } } int main() { scanf( %d%d%d%d , &N, &Q, &A, &B); memset(t, 0, sizeof(t)); root = CreateNew(1, Q); for (int i = 1; i <= N; i++) { if (i > 1) { if (A < B) { long double opt = FindOpt(root); apex[i] = opt; int l(t[root].son[0]), r(t[root].son[1]); if (opt - t[root].l > eps) { l = CreateNew(t[root].l, opt, t[root].a, t[root].b, t[root].c, t[root].son[0], 0); if (t[root].son[0]) t[t[root].son[0]].fa = l; t[l].fa = root; } if (t[root].r - opt > eps) { r = CreateNew(opt, t[root].r, t[root].a, t[root].b, t[root].c, 0, t[root].son[1]); if (t[root].son[1]) t[t[root].son[1]].fa = r; t[r].fa = root; } if (l) MarkX(l, A); if (r) MarkX(r, B); t[root].c = t[root].F(opt); t[root].son[0] = l, t[root].son[1] = r, t[root].l = opt + A, t[root].r = opt + B; t[root].a = t[root].b = t[root].da = t[root].db = t[root].dc = t[root].dx = 0; } else MarkX(root, A); } double x = Read(); MarkY(root, 1, -2 * x, x * x); } long double opt = FindOpt(root); double sum = t[root].F(opt); for (int i = N; i >= 1; i--) { ans[i] = opt; if (opt > apex[i] + B) opt -= B; else if (opt < apex[i] + A) opt -= A; else opt = apex[i]; } for (int i = 1; i <= N; i++) printf( %.10f%c , (double)ans[i], i < N ? : n ); printf( %.10f n , sum); return 0; }
|
#include <bits/stdc++.h> using namespace std; template <class T> struct rge { T b, e; }; template <class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }; template <class A, class B> ostream &operator<<(ostream &os, pair<A, B> p) { return os << ( << p.first << , << p.second << ) ; } template <class T> ostream &operator<<(ostream &os, rge<T> d) { os << [ ; for (auto it = d.b; it != d.e; it++) os << (it == d.b ? : , ) << *it; return os << ] ; } const int N = 1e5 + 5; const long long inf = 1e18; long long stones[N], frogs[N]; int n, jump; bool can(long long x) { for (int i = (1); i <= ((n)); i += (+1)) { frogs[i] = 0; } frogs[0] = x; int l = 0, r = 1; while (l < n) { while (frogs[l] > 0) { while (r <= n && stones[r] - frogs[r] <= 0) { r++; } if (l + jump < r) { return false; } long long add = min(frogs[l], stones[r] - frogs[r]); frogs[r] += add; frogs[l] -= add; } l++; r = max(l + 1, r); } return true; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15); cin >> n >> jump; for (int i = (1); i <= ((n - 1)); i += (+1)) { cin >> stones[i]; } stones[n] = inf; long long lo = 0, hi = inf; while (lo + 1 < hi) { long long mid = (lo + hi) / 2; if (can(mid)) { lo = mid; } else { hi = mid; } } while (can(lo + 1)) { lo++; } cout << lo << n ; return 0; }
|
#include <bits/stdc++.h> using namespace std; std::vector<int> v[100005]; int dist[100005]; void dfs(int s, int par) { if (par != -1) dist[s] = dist[par] + 1; for (int i = 0; i < v[s].size(); i++) { if (par != v[s][i]) dfs(v[s][i], s); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t = 1, xx, x = 0, y = 0, cc, m, k, n; cin >> t; while (t--) { int a, b, da, db; cin >> n >> a >> b >> da >> db; for (int i = 1; i < n; i++) { cin >> x >> y; v[x].push_back(y); v[y].push_back(x); dist[i] = 0; } dist[n] = 0; dfs(a, -1); int ab = dist[b]; int farest, mx = -1; for (int i = 1; i < n + 1; i++) { if (mx < dist[i]) { mx = dist[i]; farest = i; } } for (int i = 1; i < n + 1; i++) dist[i] = 0; dfs(farest, -1); int diameter = -1; for (int i = 1; i < n + 1; i++) diameter = max(diameter, dist[i]); if (ab <= da || 2 * da >= diameter || 2 * da >= db) cout << Alice << endl; else cout << Bob << endl; for (int i = 1; i < n + 1; i++) v[i].clear(); } return 0; }
|
#include <bits/stdc++.h> using namespace std; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << ( << p.first << , << p.second << ) ; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << { ; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << , ; os << *it; } return os << } ; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << [ ; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << , ; os << *it; } return os << ] ; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { os << [ ; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << , ; os << *it; } return os << ] ; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << [ ; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << , ; os << it->first << = << it->second; } return os << ] ; } void faltu() { cerr << endl; } template <typename T> void faltu(T a[], int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ; cerr << endl; } template <typename T, typename... hello> void faltu(T arg, const hello &...rest) { cerr << arg << ; faltu(rest...); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int n, s; cin >> n; s = sqrt(n); if (n == 1) { cout << 0 << endl; continue; } else { if (s * s == n) { cout << 2 * s - 2 << endl; } else if ((s + 1) * s >= n) { cout << 2 * s - 1 << endl; } else if ((s + 1) * (s + 1) >= n) { cout << 2 * s << endl; } } } return 0; }
|
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, a[maxn], b[maxn], t[maxn]; bool check(int num, int pos) { t[pos] = num; if (pos == n) return true; for (int i = 0; i <= 3; i++) { if ((num | i) == a[pos] && (num & i) == b[pos]) return check(i, pos + 1); } return false; } int main() { scanf( %d , &n); for (int i = 1; i < n; i++) { scanf( %d , &a[i]); } for (int i = 1; i < n; i++) { scanf( %d , &b[i]); } for (int i = 0; i <= 3; i++) { if (check(i, 1)) { printf( YES n ); for (int j = 1; j <= n; j++) { printf( %d , t[j]); } return 0; } } printf( NO ); }
|
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 10; const int M = 5 * N; const int OO = 1000000000; int ans = 0; int anum = 0; int i; int n; int result; int sum[N]; int tree[M]; string s; int lowbit(int x) { return x & (-x); } int min(int a, int b) { return a < b ? a : b; } int ask(int x) { int i = x; int result = OO; while (i > 0) { result = min(result, tree[i]); i -= lowbit(i); } return result; } void update(int x, int y) { int i = x; while (i < M) { tree[i] = min(tree[i], y); i += lowbit(i); } } int main() { getline(cin, s); n = s.size(); for (i = 0; i < n; i++) if (s[i] >= a && s[i] <= z ) s[i] = s[i] - a + A ; for (i = 0; i < n; i++) { sum[i + 1] = sum[i]; if (s[i] == A || s[i] == E || s[i] == I || s[i] == O || s[i] == U ) sum[i + 1]--; else sum[i + 1] += 2; } for (i = 0; i <= n; i++) sum[i] += 2 * n; for (i = 0; i < M; i++) tree[i] = OO; update(sum[0], 0); for (i = 1; i <= n; i++) { result = ask(sum[i]); if (i - result > ans) { ans = i - result; anum = 0; } if (i - result == ans) anum++; update(sum[i], i); } if (ans > 0) cout << ans << << anum << n ; else cout << No solution n ; return 0; }
|
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAX_N = 1e5 + 50; int w[MAX_N]; void solve() { int n, m; cin >> n >> m; long long ret = ((long long)w[n] + (long long)w[m] - 1LL) * 2LL; cout << ret % MOD << n ; } void precal() { w[0] = 0; w[1] = 1; w[2] = 2; for (int i = (3); i < (MAX_N); ++i) { w[i] = w[i - 1] + w[i - 2]; w[i] %= MOD; } } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); precal(); solve(); return 0; }
|
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 2e5; int p[MAXN + 10], rub[MAXN + 10]; bool mark[MAXN + 10]; bool palin(int x) { stringstream sst; sst << x; string s; sst >> s; for (int i = 0; i < s.length(); i++) if (s[i] != s[s.length() - i - 1]) return false; return true; } int main() { ios::sync_with_stdio(false); rub[1] = 1; cerr << palin(121) << endl; long double a, b; cin >> a >> b; for (int i = 2; i <= MAXN; i++) { if (palin(i)) { rub[i] = rub[i - 1] + 1; } else rub[i] = rub[i - 1]; if (!mark[i]) { p[i] = p[i - 1] + 1; for (int j = i + i; j <= MAXN; j += i) mark[j] = true; } else p[i] = p[i - 1]; } long double x = a / b; int Max = 0; for (int i = 1; i <= MAXN; i++) if ((long double)p[i] / (long double)rub[i] <= x) Max = i; cout << Max << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; const int SZ = 200005; vector<int> graph[SZ]; int par[SZ]; int dst[SZ]; int tot; void dfs(int x, int crt) { par[x] = crt; tot++; for (int nxt : graph[x]) { if (par[nxt]) continue; dfs(nxt, crt); } } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) { graph[i].clear(); par[i] = 0; dst[i] = 0; } for (int i = 1; i <= n; i++) { int x; cin >> x; graph[i].push_back(x); } int pp = 0; for (int i = 1; i <= n; i++) { if (par[i]) continue; tot = 0; dfs(i, ++pp); dst[pp] = tot; } for (int i = 1; i <= n; i++) cout << dst[par[i]] << ; cout << n ; } return 0; }
|
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const int maxn = 1e6 + 100; const double EPS = 1e-12; struct point { double x, y; }; string a[11] = { zero , one , two , three , four , five , six , seven , eight , nine , ten }; string b[11] = { , , twen , thir , for , fif , six , seven , eigh , nine }; string c[11] = { , , , thir , four , fif , six , seven , eigh , nine }; int n; int main() { cin >> n; if (n <= 10) { cout << a[n] << endl; return 0; } if (n < 20) { if (n == 11) cout << eleven << endl; else if (n == 12) cout << twelve << endl; else cout << c[n % 10] << teen << endl; return 0; } if (n % 10 == 0) { cout << b[n / 10] << ty << endl; return 0; } cout << b[n / 10] << ty- << a[n % 10] << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; int64_t read() { bool b = 0; int64_t n = 0; char c = getchar(); for (; !(( 0 ) <= (c) && (c) <= ( 9 )); c = getchar()) b = (c == - ); for (; (( 0 ) <= (c) && (c) <= ( 9 )); c = getchar()) n = 10 * n + (c - 0 ); if (b) n = -n; return n; } const int64_t N = 1e5 + 10; int64_t _log[2 * N], ss[2 * N][20], bl[N][20]; vector<int64_t> adj[N]; int64_t h[N], first[N]; vector<int64_t> et; int64_t V[N]; int64_t n, q; int64_t tin[N], tout[N], t = -1; int64_t stlen, sth; int64_t lp[N]; int64_t st[2 * N]; void calc(int64_t i, int64_t k) { st[i] = st[i << 1] + st[i << 1 | 1] + lp[i] * k; } void app(int64_t i, int64_t vv, int64_t k) { st[i] += vv * k; if (i < stlen) lp[i] += vv; } void build(int64_t l, int64_t r) { int64_t k = 2; for (l += stlen, r += stlen - 1; l > 1; k <<= 1) { l >>= 1, r >>= 1; for (int64_t i = r; i >= l; --i) calc(i, k); } } void push(int64_t l, int64_t r) { int64_t s = sth, k = 1 << (sth - 1); for (l += stlen, r += stlen - 1; s > 0; --s, k >>= 1) for (int64_t i = l >> s; i <= r >> s; ++i) if (lp[i] != 0) { app(i << 1, lp[i], k); app(i << 1 | 1, lp[i], k); lp[i] = 0; } } void add(int64_t l, int64_t r, int64_t vv) { push(l, l + 1), push(r - 1, r); int64_t l0 = l, r0 = r, k = 1; for (l += stlen, r += stlen; l < r; l >>= 1, r >>= 1, k <<= 1) { if (l & 1) app(l++, vv, k); if (r & 1) app(--r, vv, k); } build(l0, l0 + 1), build(r0 - 1, r0); } int64_t query(int64_t l, int64_t r) { int64_t l0 = l, r0 = r; push(l, l + 1), push(r - 1, r); int64_t res = 0; for (l += stlen, r += stlen; l < r; l >>= 1, r >>= 1) { if (l & 1) res += st[l++]; if (r & 1) res += st[--r]; } l = l0, r = r0; return res; } void _clog() { for (int64_t i = 2; i < 2 * N; ++i) _log[i] = _log[i >> 1] + 1; } void clca() { int64_t n = et.size(); for (int64_t i = 0; (i) < (n); ++(i)) ss[i][0] = et[i]; for (int64_t k = 1; (1 << k) <= n; ++k) for (int64_t i = 0; i + (1 << k) <= n; ++i) { int64_t j = i + (1 << (k - 1)); if (h[ss[i][k - 1]] < h[ss[j][k - 1]]) ss[i][k] = ss[i][k - 1]; else ss[i][k] = ss[j][k - 1]; } } int64_t lca(int64_t l, int64_t r) { l = first[l], r = first[r]; if (r < l) swap(l, r); int64_t k = _log[r - l + 1]; int64_t a = ss[l][k], b = ss[r - (1 << k) + 1][k]; if (h[a] < h[b]) return a; else return b; } void pdfs(int64_t v, int64_t p) { first[v] = int64_t((et).size()); tin[v] = ++t; et.push_back(v); bl[v][0] = p; for (int64_t i = 0; (i) < (19); ++(i)) bl[v][i + 1] = bl[bl[v][i]][i]; for (int64_t c : adj[v]) { if (c == p) continue; h[c] = h[v] + 1; pdfs(c, v); et.push_back(v); } tout[v] = t; } int64_t rlca(int64_t root, int64_t l, int64_t r) { return lca(l, root) ^ lca(r, root) ^ lca(l, r); } int64_t up(int64_t v, int64_t first) { for (int64_t i = 19; first && i >= 0; --i) if ((1 << i) <= first) v = bl[v][i], first -= (1 << i); return v; } int64_t qsub(int64_t v) { return query(tin[v], tout[v] + 1); } void msub(int64_t v, int64_t vv) { add(tin[v], tout[v] + 1, vv); } int main() { ; n = read(), q = read(), stlen = n; sth = 8 * 4 - __builtin_clz(stlen); ; for (int64_t i = 0; (i) < (n); ++(i)) V[i] = read(); int64_t a, b; for (int64_t i = 0; (i) < (n - 1); ++(i)) { a = read() - 1, b = read() - 1; adj[a].push_back(b); adj[b].push_back(a); } _log[1] = 0; _clog(); pdfs(0, 0); clca(); ; for (int64_t i = 0; (i) < (n); ++(i)) ; ; ; ; for (int64_t i = 0; (i) < (n); ++(i)) ; ; ; for (int64_t i = 0; (i) < (n); ++(i)) st[stlen + tin[i]] = V[i]; build(0, n); int64_t op, root = 0; while (q--) { op = read(); if (op == 1) { root = read() - 1; } else if (op == 2) { int64_t v = rlca(root, read() - 1, read() - 1); int64_t vv = read(); if (root == v) { msub(0, vv); } else if (lca(v, root) == v) { ; msub(0, vv), msub(up(root, h[root] - h[v] - 1), -vv); } else { msub(v, vv); } } else { int64_t v = read() - 1; ; assert(op == 3); if (root == v) { printf( %lld n , qsub(0)); } else if (lca(v, root) == v) { ; ; printf( %lld n , qsub(0) - qsub(up(root, h[root] - h[v] - 1))); } else { printf( %lld n , qsub(v)); } }; for (int64_t i = 0; (i) < (n); ++(i)) ; ; ; } return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char board[n][n]; bool even = true; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> board[i][j]; for (int i = 0; i < n; i++) { int c = 0; for (int j = 0; j < n; j++) { if (i - 1 >= 0 and board[i - 1][j] == o ) c++; if (i + 1 < n and board[i + 1][j] == o ) c++; if (j - 1 >= 0 and board[i][j - 1] == o ) c++; if (j + 1 < n and board[i][j + 1] == o ) c++; if (c % 2 == 1) even = false; } } if (even) cout << YES << endl; else cout << NO << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; const long long int MAX = 1e7 + 7; const long long int MOD = 1000000007; void fast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int main() { fast(); long long int TEST_CASES = 1; while (TEST_CASES--) { int n; cin >> n; vector<pair<string, int>> v(n); map<string, long long int> mp, now; for (long long int(i) = 0; (i) < n; (i)++) { cin >> v[i].first >> v[i].second; mp[v[i].first] += v[i].second; } string mxs; long long int mx = INT_MIN; for (auto i : mp) { if (mx < i.second) { mx = i.second; mxs = i.first; } } string str; for (int i = 0; i < n; i++) { now[v[i].first] += v[i].second; if (mp[v[i].first] == mx && now[v[i].first] >= mx) { str = v[i].first; break; } } cout << str << n ; } return 0; }
|
#include <bits/stdc++.h> using namespace std; typedef struct { int freq; char l; } db; int comp(const void *a, const void *b) { db *x = (db *)a; db *y = (db *)b; return x->freq - y->freq; } int main() { db aa[30]; db e; string str; int let[30], sz, i, cnt, k, d, j; while (cin >> str) { cin >> d; memset(let, 0, sizeof(let)); sz = str.length(); for (i = 0; i < sz; i++) { let[str[i] - a ]++; } cnt = 0; k = 0; for (i = 0; i < 26; i++) { if (let[i]) { cnt++; aa[k].l = i + a ; aa[k].freq = let[i]; k++; } } qsort(aa, k, sizeof(db), comp); sz = str.size(); for (i = 0; i < k; i++) { if (d == 0) break; for (j = 0; j < str.size() && d > 0; j++) { if (str[j] == aa[i].l) { str.erase(j, 1); j--; let[aa[i].l - a ]--; d--; } } } cnt = 0; for (i = 0; i < 26; i++) { if (let[i]) cnt++; } cout << cnt << endl; cout << str << endl; } return 0; }
|
#include <bits/stdc++.h> char c[10005]; int main() { int i, j, k, n, m; int x0 = 0, x = 0, y0 = 0, y = 0; scanf( %d%s , &n, c + 1); for (i = 1; i <= n; i++) { if (!x0 && c[i] == R ) x0 = i; if (c[i] == R ) x = i; if (!y0 && c[i] == L ) y0 = i; if (c[i] == L ) y = i; } if (!x0) printf( %d %d n , y, y0 - 1); else if (!y0) printf( %d %d n , x0, x + 1); else printf( %d %d n , x0, x); return 0; }
|
#include <bits/stdc++.h> using namespace std; int blk_size; struct node { int l, r, id; long long int ans = 0; }; bool compare(node a, node b) { if (a.l / blk_size != b.l / blk_size) return (a.l) / blk_size < (b.l) / blk_size; return a.r < b.r; } bool compare2(node a, node b) { return a.id < b.id; } long long int freq[3000001]; int main() { ios_base::sync_with_stdio(false); ; int n, m, k; cin >> n >> m >> k; std::vector<int> a(n), pxor(n + 1); for (int i = 0; i < n; i++) cin >> a[i]; pxor[0] = 0; for (int i = 1; i <= n; i++) pxor[i] = pxor[i - 1] ^ a[i - 1]; blk_size = sqrt(n + 1); std::vector<node> q(m); for (int i = 0; i < m; i++) { cin >> q[i].l >> q[i].r; q[i].id = i; } sort(q.begin(), q.end(), compare); int start = 0, end = 0; long long int ans = 0; freq[0] = 1; for (int i = 0; i < m; i++) { int l = q[i].l - 1, r = q[i].r; while (start > l) { start--; ans += freq[pxor[start] ^ k]; freq[pxor[start]]++; } while (start < l) { freq[pxor[start]]--; ans -= freq[pxor[start] ^ k]; start++; } while (end > r) { freq[pxor[end]]--; ans -= freq[pxor[end] ^ k]; end--; } while (end < r) { end++; ans += freq[pxor[end] ^ k]; freq[pxor[end]]++; } q[i].ans = ans; } sort(q.begin(), q.end(), compare2); for (int i = 0; i < m; i++) printf( %lld n , q[i].ans); return 0; }
|
#include <bits/stdc++.h> const long long MOD = 1000000007; int N, K; long long a[5002], FUL[5001]; long long inv[5001]; long long O; long long POWER(long long a, long long b) { long long r = 1; for (; b; b >>= 1) { if (b & 1) r = r * a % MOD; a = a * a % MOD; } return r; } int main() { scanf( %d%d , &N, &K); if (N == 1) { printf( %lld n , K % MOD); return 0; } FUL[0] = 1; for (int i = 1; i <= N; i++) { scanf( %lld , a + i); FUL[i] = 0; for (int j = i; j; j--) FUL[j] = (FUL[j] * a[i] - FUL[j - 1] + MOD) % MOD; FUL[0] = FUL[0] * a[i] % MOD; } inv[1] = 1; for (int i = 2; i <= N; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD; for (int i = 1; i <= N; i++) { static long long pol[5000]; pol[N - 1] = (MOD - FUL[N]) % MOD; for (int j = N - 2; ~j; j--) pol[j] = (pol[j + 1] * a[i] - FUL[j + 1] + MOD) % MOD; long long TPW = 1; for (int a = 0; a < N && a < K; a++) { TPW = TPW * inv[N] % MOD * (K - a) % MOD; O = (O + pol[a] % MOD * inv[a + 1] % MOD * TPW) % MOD; } } printf( %lld n , O); return 0; }
|
#include <bits/stdc++.h> using namespace std; using ld = long double; template <class T> inline T gcd(T a, T b) { return !a ? b : gcd(b % a, a); } template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); } mt19937 rnd(time(0)); const int INF = 1e9; const long long LLINF = 1e15; void solve() { int n, m; cin >> n >> m; string a, b; cin >> a >> b; int ans = 0; vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp[i][j] = max(0, max(dp[i - 1][j], dp[i][j - 1]) - 1); if (a[i - 1] == b[j - 1]) { dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2); } ans = max(ans, dp[i][j]); } } cout << ans << n ; return; } signed main() { ios_base ::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t = 1; while (t-- > 0) { solve(); } return 0; }
|
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << << x << ; } void __print(const char *x) { cerr << << x << ; } void __print(const string &x) { cerr << << x << ; } void __print(bool x) { cerr << (x ? true : false ); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << { ; __print(x.first); cerr << , ; __print(x.second); cerr << } ; } template <typename T> void __print(const T &x) { int f = 0; cerr << { ; for (auto &i : x) cerr << (f++ ? , : ), __print(i); cerr << } ; } void _print() { cerr << ] n ; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << , ; _print(v...); } void solve() { long long int l, r; cin >> l >> r; long long int mposs = (r - 1) >> 1; if (r - mposs >= l) cout << mposs << n ; else cout << r % l << n ; } signed main() { int t = 1; cin >> t; while (t--) { solve(); } return 0; }
|
#include <bits/stdc++.h> using namespace std; long long int ans, sum, pro; string s, str; long long int solve(int st, int end, string z) { long long int sum2 = 0, pro2 = 1; for (int i = st; i <= end; i++) { if (z[i] == + ) { sum2 += pro2; pro2 = 1; } else if (i % 2 == 0) pro2 *= s[i] - 0 ; } return sum2 + pro2; } int main() { cin >> s; str = 1* ; str += s; str += *1 ; s = str; for (int i = 1; i < s.size(); i += 2) { if (s[i] == + ) continue; for (int j = i + 2; j < s.size(); j += 2) { if (s[j] == * ) { sum = 0, pro = 1; for (int k = 0; k < s.size(); k++) { if (k == i) pro *= solve(i + 1, j - 1, s); else if (k >= i && k <= j) continue; else if (s[k] == + ) { sum += pro; pro = 1; } else if (k % 2 == 0) pro *= s[k] - 0 ; } sum += pro; ans = max(ans, sum); } } } cout << ans << n ; }
|
#include <bits/stdc++.h> using namespace std; bool bad[105]; string A[105]; bool check(string a, string b) { if ((int)a.size() != (int)b.size()) return false; for (int i = 0; i < (int)a.size(); i++) if (tolower(a[i]) != tolower(b[i])) return false; return true; } int main() { int n, i, j, k; char c, c2; string s; cin >> n; for (i = 0; i < n; i++) cin >> A[i]; cin >> s >> c; for (i = 0; i < n; i++) { for (j = 0; j < (int)s.size(); j++) if (check(s.substr(j, (int)A[i].size()), A[i])) for (k = j; k < j + (int)A[i].size(); k++) bad[k] = true; } for (i = 0; i < (int)s.size(); i++) if (bad[i]) { if (isupper(s[i])) c2 = toupper(c); else c2 = tolower(c); if (s[i] == c2) { if (isupper(s[i])) { for (c2 = A ; c2 <= Z ; c2++) if (c2 != s[i]) { s[i] = c2; break; } } else { for (c2 = a ; c2 <= z ; c2++) if (c2 != s[i]) { s[i] = c2; break; } } } else s[i] = c2; } cout << s; return 0; }
|
#include <bits/stdc++.h> using std ::vector; template <typename T> T max(T x, T y) { return (x > y) ? x : y; } template <typename T> T min(T x, T y) { return (x < y) ? x : y; } template <typename T> bool chkmax(T &x, T y) { return (x >= y) ? 0 : (x = y, 1); } template <typename T> bool chkmin(T &x, T y) { return (x <= y) ? 0 : (x = y, 1); } template <typename T> T read(T &in) { in = 0; char ch; T f = 1; while (!isdigit(ch = getchar())) if (ch == - ) f = -1; while (isdigit(ch)) in = in * 10 + ch - 0 , ch = getchar(); return in *= f; } static const int max1 = 100000 + 11; static const int BIT = 16; bool vis[max1]; vector<int> fac[max1]; struct Node { Node *ch[2]; int v; Node() { ch[0] = ch[1] = NULL, v = 100001; } }; struct Trie { Node *root; Trie() { root = new Node; } void Insert(int x) { Node *o = root; chkmin(o->v, x); for (int i = (BIT), ir = (0); i >= (ir); --i) { int c = x >> i & 1; if (!o->ch[c]) o->ch[c] = new Node; o = o->ch[c]; chkmin(o->v, x); } } } T[max1]; void Init(int n = 100000) { for (int i = 1; i <= n; ++i) for (int j = i; j <= n; j += i) fac[j].push_back(i); } void Modify(int x) { if (vis[x]) return; vis[x] = 1; for (vector<int>::iterator i = fac[x].begin(); i != fac[x].end(); ++i) T[*i].Insert(x); } int Query(int x, int k, int s) { if (x % k) return -1; s -= x; int c = 0; Node *o = T[k].root; if (o->v > s) return -1; for (int i = (BIT), ir = (0); i >= (ir); --i) { int w = x >> i & 1; if (s < (1 << i) || o->ch[1] && o->ch[1]->v > s) o = o->ch[0]; else if (!o->ch[0]) o = o->ch[1], c += 1 << i; else if (!o->ch[1]) o = o->ch[0]; else if (w) o = o->ch[0]; else o = o->ch[1], c += 1 << i; } return c; } int main() { int q; read(q); Init(); while (q--) { int o, x, k, s; read(o), read(x); if (o == 1) { Modify(x); } else { read(k), read(s); printf( %d n , Query(x, k, s)); } } return 0; }
|
#include <bits/stdc++.h> using namespace std; int ans, n, a[10005], cnt, f, i, j, vis[10005]; int main() { scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a[i]); } ans = 0; f = 0; cnt = 0; memset(vis, 0, sizeof vis); for (i = 0; i < n; i++) { if (!f) { for (j = 0; j < n; j++) { if (cnt >= a[j] && !vis[j]) { vis[j] = 1; cnt++; } } } else { for (j = n - 1; j >= 0; j--) { if (cnt >= a[j] && !vis[j]) { vis[j] = 1; cnt++; } } } if (cnt == n) { break; } else { ans++; } f = 1 - f; } printf( %d , ans); return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], ans = 0, maxi = 0; for (int i = 0; i < 7; i++) { cin >> a[i]; maxi += a[i]; } int t; if (maxi >= n) t = 1; else if (n % maxi == 0) { t = n / maxi; } else { t = n / maxi + 1; } while (t--) { for (int i = 0; i < 7; i++) { n -= a[i]; if (n <= 0) { ans = i + 1; break; } } } cout << ans << n ; return 0; }
|
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000 ) using namespace std; int b[500][100005], c[500]; int main() { srand(time(0)); int n, m, i, j, k; scanf( %d %d , &n, &m); map<int, vector<int> > a; for (i = 0; i < n; i++) { scanf( %d , &k); if (k <= n) a[k].push_back(i + 1); } vector<int> v; map<int, vector<int> >::iterator it; for (it = a.begin(); it != a.end(); it++) if (it->first > it->second.size()) v.push_back(it->first); for (i = 0; i < v.size(); i++) a.erase(v[i]); k = 0; for (it = a.begin(); it != a.end(); it++) { c[k] = it->first; for (i = 0; i < it->second.size(); i++) b[k][it->second[i]] = 1; for (i = 1; i <= n; i++) b[k][i] += b[k][i - 1]; k++; } while (m--) { scanf( %d %d , &i, &j); int cnt = 0; for (n = 0; n < k; n++) if (c[n] == b[n][j] - b[n][i - 1]) cnt++; printf( %d n , cnt); } return 0; }
|
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } int num[26]; int main() { int T; scanf( %d , &T); while (T--) { int n; string s, t; cin >> n >> s >> t; int rev = 0, flg = 0; memset(num, 0, sizeof(num)); for (int i = 0; i < n; i++) { for (int j = s[i] - a + 1; j < 26; j++) { rev += num[j]; } num[s[i] - a ]++; } for (int i = 0; i < 26; i++) { if (num[i] >= 2) flg = 1; } memset(num, 0, sizeof(num)); for (int i = 0; i < n; i++) { for (int j = t[i] - a + 1; j < 26; j++) { rev += num[j]; } num[t[i] - a ]++; } for (int i = 0; i < 26; i++) { if (num[i] >= 2) flg = 1; } sort(s.begin(), s.end()); sort(t.begin(), t.end()); if (s != t || (rev % 2 != 0 && !flg)) puts( NO ); else puts( YES ); } return 0; }
|
#include <bits/stdc++.h> using namespace std; long long dr[] = {-1, 1, 0, 0, -1, 1, -1, 1}; long long dc[] = {0, 0, -1, 1, -1, -1, 1, 1}; int main() { long long T; cin >> T; while (T--) { string a, b; cin >> a >> b; if (a < b) { cout << a << n ; continue; } bool f = 0; long long sz = min(a.size(), b.size()); long long loop = 0; for (long long i = 0; i < sz; i++) { if (a[i] < b[i]) { f = 1; break; } else { long long indx = -1; char mn = b[i]; for (long long j = i + 1; j < a.size(); j++) { if (a[j] <= mn) { mn = a[j]; indx = j; } } if (indx == -1 and a[i] > b[i]) { break; } else if (indx == -1 and a[i] == b[i]) { continue; } if (a[i] == a[indx]) continue; swap(a[i], a[indx]); loop++; if (a < b) { f = 1; } break; } } if (f == 1) { cout << a << n ; } else { cout << --- << n ; } } return 0; }
|
#include <bits/stdc++.h> using namespace std; inline long long LAKLSNCJKQ() { char c = getchar(); if (32281 > 23346) { long long SJQTNVYTHY; SJQTNVYTHY = 890; long long VLABDWDNOG; double QHJMZGOBOX; bool SJAZLHXFNS; } long long x = 0; double IBTBRLYCXT; IBTBRLYCXT = 22204; if (IBTBRLYCXT) { if (28191 > 11727) { if (31516 > 10166) { short OIYWZWGUMU; OIYWZWGUMU = 32597; bool KBORLDDWJN; KBORLDDWJN = 28507; if (15624 > 14783) { double XPAYQSVEQU; bool KTQMTWTZFW; } bool ATVFEDBUXZ; ATVFEDBUXZ = 5419; if (ATVFEDBUXZ) { short YGYZAWOKXY; } } double BQWXBOXCPY; BQWXBOXCPY = 6361; } long long VAOVGFEAUK; long long FEIASNIVBT; FEIASNIVBT = 18457; } bool f = 0; if (22244 > 7895) { short MVPVMWUJOD; MVPVMWUJOD = 28548; if (MVPVMWUJOD) { if (13366 > 13803) { bool XDCCNBURPK; XDCCNBURPK = 13989; long long UPCCKTPSFJ; UPCCKTPSFJ = 5412; } } } for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); if (331 > 31276) { double XUKCKKWRRB; XUKCKKWRRB = 2944; if (XUKCKKWRRB) { short KHPLISVQGN; KHPLISVQGN = 21673; if (10023 > 7274) { if (3328 > 5414) { bool JYTIEGOKKQ; } bool XBXALUHDZX; XBXALUHDZX = 9228; if (XBXALUHDZX) { long long HEXFFVFFRE; } short FLWZRFLJBM; FLWZRFLJBM = 6345; if (FLWZRFLJBM) { double YOOXQTHBXQ; long long SWBPNZOBPM; short MIMUYITJME; long long LVFSTHJESV; } } } if (7446 > 10128) { double MQGRWENFXI; MQGRWENFXI = 16177; if (31692 > 5532) { bool VEXACEEMMA; VEXACEEMMA = 5606; if (11065 > 16359) { double EOSLBZHSUN; } if (9892 > 13627) { short GMZDPSFDZG; long long JFHPKLADKT; bool FYESZAROVH; } } long long LXVYMIPDCK; } short XYCYVTPGLD; XYCYVTPGLD = 25583; } for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (23117 > 2644) { double LTCKFKKIVJ; if (17820 > 22924) { double VKBSTTDPFF; VKBSTTDPFF = 26648; if (VKBSTTDPFF) { if (16774 > 5619) { long long AZVUQUXROT; double GISFTHWSVA; long long YWTCSRLTNK; short EYBHYCANBM; } bool MSQJZZIUHR; MSQJZZIUHR = 14372; double BTTXSQBCBR; BTTXSQBCBR = 28650; } if (17173 > 31740) { if (10763 > 16891) { short RDTWNHMTID; } double OUHOEPPBMO; bool KXNZUQYVPS; } if (17326 > 28582) { bool WWXKPIIHCE; WWXKPIIHCE = 30063; } } } if (f) x = -x; return x; if (17432 > 28544) { if (828 > 28220) { long long FNDIWALLAX; FNDIWALLAX = 31062; if (FNDIWALLAX) { long long TYAMBDKTLO; TYAMBDKTLO = 22072; if (23808 > 27160) { long long DTDGOVKVWS; double NZZOJGQYGA; long long UMAYDUQNKS; } } long long EKBLPPACGT; EKBLPPACGT = 26135; if (EKBLPPACGT) { long long OWRLBFHLLO; OWRLBFHLLO = 9211; if (OWRLBFHLLO) { double SXDKTWOMBI; } bool GKCDYTVHSG; if (5365 > 24741) { double IIIWGIIJSZ; long long FDJQMWIQZF; } } bool UKNSMRJBST; UKNSMRJBST = 11817; if (UKNSMRJBST) { double KSQRSYJYHA; if (10789 > 3838) { double QUJBIILQGR; double RJBINMMZGZ; long long IJFIBQPBAT; } short XVZPFSLVNQ; } } if (27853 > 9859) { if (7496 > 18297) { if (9508 > 1820) { long long BRRIBTPAGH; double IZYQBJHUQZ; } } } if (13069 > 13617) { if (28990 > 9166) { bool IPTBNMVVTS; IPTBNMVVTS = 20463; } short BRZLWCLFWL; BRZLWCLFWL = 29016; } } } using namespace std; const long long Mask = (1ll << 30) - 1, inf = 1e18; long long n; char s[600005]; long long PKCNKSQOWC[600005][20], NOQEFVKSSX[600005]; long long PASLQWKEND1, PASLQWKEND2, a26, a30, PASLQWKEND; map<long long, long long> ZLMQOGHJFF; long long OZXICPQWDF[600005], ODIUVNKJQW[600005]; inline long long ask(long long l, long long r) { if (l > r) swap(l, r); long long k = NOQEFVKSSX[r - l + 1]; long long RJYRZIFLXF; RJYRZIFLXF = 4416; return min(PKCNKSQOWC[r][k], PKCNKSQOWC[l + (1 << k) - 1][k]); if (11184 > 12519) { short BJCZAVIHQU; BJCZAVIHQU = 21585; double JTPTTPPEIW; if (7270 > 10837) { bool YXCIVCJQUR; YXCIVCJQUR = 18023; if (YXCIVCJQUR) { short HMEDVWYZAD; double BIZBSPXTPI; BIZBSPXTPI = 19761; } bool EPFHBLNBQV; EPFHBLNBQV = 16855; if (EPFHBLNBQV) { if (8920 > 87) { long long GUTVDVDAUP; long long TQQSGXKQKB; long long CWYOQFLQWS; } } } bool MFGSZBWZXL; } } void print(long long x, long long y) { if (!y) { printf( %lld n , x); return; short PQCMYOUFVD; PQCMYOUFVD = 21379; if (PQCMYOUFVD) { short KYVFDSGZVL; KYVFDSGZVL = 28299; if (KYVFDSGZVL) { if (14693 > 25213) { short FEZICBMRZI; long long VDNSTGUSLU; long long IHWUUSLHLQ; } short VRRFLEUIWY; VRRFLEUIWY = 16770; if (VRRFLEUIWY) { bool HKMSYIJLMH; short FTMBCPPWWL; long long HBVFUJHJXC; } long long AWEWSLADGZ; AWEWSLADGZ = 32404; if (AWEWSLADGZ) { long long TUOIXVWQLK; bool VNAAHTOMCM; double RYYBVYDOFI; } } double PUKHNXGHLR; PUKHNXGHLR = 11134; } } printf( %lld , y); bool BFZFAJAHJP; BFZFAJAHJP = 27702; if (BFZFAJAHJP) { long long GRJKVDSUPK; GRJKVDSUPK = 31083; if (GRJKVDSUPK) { if (7344 > 21031) { if (13430 > 6930) { long long YZTEKYCEXH; double RMGXTHTCXE; short WOFOSURDYX; } double KYVQLKWMKV; } long long CJSSCLMZUU; CJSSCLMZUU = 24416; if (1470 > 27735) { long long MMUICAJFAP; if (5792 > 14230) { double DPSXHZDHOT; long long NPKNGIBVQT; double UVEGIPSWFF; short SRFYCDCVFU; short CJRMQOIKBI; } } } if (11216 > 22837) { long long MNKZBFRGFJ; short ICSTNOPDLO; ICSTNOPDLO = 6349; if (ICSTNOPDLO) { if (27645 > 14013) { long long FOLNJLTMDX; long long RQGHCPFZMY; long long CBANSDKKKB; long long RDOHCWWIPX; } if (10160 > 24441) { double VSVQHUFVMW; } } long long XPTKNPPOHX; XPTKNPPOHX = 18014; if (3933 > 31689) { long long FNXJPICBKA; } } double BAGZRPCXQH; BAGZRPCXQH = 11896; } long long now = inf / 10; long long QLXZPYBXTJ; QLXZPYBXTJ = 17162; while (now > x && now >= 10) putchar( 0 ), now /= 10; if (2226 > 31142) { long long EDWJMGBWHJ; EDWJMGBWHJ = 32093; if (EDWJMGBWHJ) { if (7027 > 23752) { if (15643 > 24958) { bool UNBRLRBRKZ; short CYZELXDDHX; bool MIKZQCQKLS; bool CVPGIILVHA; } } long long QYISVVTYAS; QYISVVTYAS = 30577; } long long XAHLGLMGRD; XAHLGLMGRD = 11996; if (XAHLGLMGRD) { long long ETKECDJAMX; ETKECDJAMX = 6319; if (28138 > 7202) { if (24397 > 24360) { bool VNTZVBCFYC; } double FNIAMKXDKC; FNIAMKXDKC = 2707; if (FNIAMKXDKC) { long long BTPDBRLEIW; short NCOLRHIITE; double HQFYCCBACD; bool GMZIUJWMFA; long long EDXJKJUBFW; } } if (8285 > 10375) { long long OCOYCBMFLM; OCOYCBMFLM = 21978; if (27175 > 15533) { short UZEPJAZTDP; double GNJDGVOAMW; double FCHIHZFDER; short OGUZXULEOL; } if (14265 > 20236) { long long KABFUJALMS; short ZGBWNAUAER; } } } } printf( %lld n , x); if (6512 > 31058) { if (20281 > 1432) { if (13622 > 17665) { if (29270 > 7054) { long long FFGDTLRVDD; long long FVQIHPGNGA; short GPQZERIEVA; } short BJGSVDUUAU; bool KVAOEUMIRF; } bool DHTVYEZTDC; if (8247 > 8501) { if (24741 > 12098) { bool IYROVUUNZX; long long WQROVRNZFF; bool JCDKQKUXWP; long long XBGJSYBGKU; } long long ZTZOASWUJT; ZTZOASWUJT = 7936; if (ZTZOASWUJT) { short BGLTBDDZXJ; } if (27819 > 5085) { long long NYCVYZFPER; long long FAGJEBIZYM; } } } long long CWQAYAGVVA; if (7808 > 24851) { long long LVDDJUADIK; LVDDJUADIK = 27710; } } } signed main() { n = LAKLSNCJKQ(), NOQEFVKSSX[0] = -1; bool OJBUOKHNZP; OJBUOKHNZP = 9527; if (OJBUOKHNZP) { long long THDITISJUK; THDITISJUK = 32453; if (THDITISJUK) { bool AEKBKKXSQJ; AEKBKKXSQJ = 4561; if (AEKBKKXSQJ) { double OTNTQJYURH; OTNTQJYURH = 8786; } if (32521 > 3021) { bool LIPPFKNCSW; if (4668 > 21251) { bool GEEJRXLMRQ; long long EQOMAXBWSR; long long YFWKKNUBNX; } } long long OCTWNVRHIS; } double IDABZUKKIV; } for (long long i = (1); i <= (n); ++i) NOQEFVKSSX[i] = NOQEFVKSSX[i >> 1] + 1; if (7728 > 10480) { long long TJWNMUJCBD; TJWNMUJCBD = 899; if (TJWNMUJCBD) { double OCLIDBOVHI; short FEHVYHHCKQ; FEHVYHHCKQ = 21844; double TIKOQFHVPD; TIKOQFHVPD = 27273; long long WIHBCOGVWF; } bool SLJQQOMDJC; SLJQQOMDJC = 27775; short ZJSCRHEQMD; } OZXICPQWDF[0] = -1; double CHVRMSFDIT; CHVRMSFDIT = 28336; for (long long i = (1); i <= (n); ++i) { scanf( %s , s + i); if (5013 > 30592) { double YYLFBDEYIA; YYLFBDEYIA = 17517; bool TNAWJTYVJW; TNAWJTYVJW = 32675; long long KZZTAJUUMW; } s[i] = ((s[i] - a + a26) % 26) + a ; bool AVCQWAUQGM; AVCQWAUQGM = 17877; if (AVCQWAUQGM) { short KNDWIIAUDN; KNDWIIAUDN = 11578; if (KNDWIIAUDN) { bool XZGWKECTXO; long long ROMCPCZVRW; } if (3031 > 28497) { if (5615 > 28550) { long long KMYCQLCMRK; long long NUJUQEZAGM; bool AQHLXZSMJF; long long GPHHMIDCDN; short MGXFDNMKLV; } double QWLZXBLCUV; QWLZXBLCUV = 11743; if (QWLZXBLCUV) { double CEMFHTAJKE; } long long MLDXLMCEZM; } bool LREWUAAYZU; short OVACEMKBUI; } long long w = LAKLSNCJKQ(); short RZYSLIYYLY; RZYSLIYYLY = 9499; w ^= (a30 & Mask); short HBIHGJNXAH; PKCNKSQOWC[i][0] = w; short TWUENILLHZ; for (long long j = (1); j <= (19); ++j) if (i >= (1 << j)) PKCNKSQOWC[i][j] = min(PKCNKSQOWC[i - (1 << (j - 1))][j - 1], PKCNKSQOWC[i][j - 1]); long long j = OZXICPQWDF[i - 1]; if (6425 > 25228) { long long OVKNAHKQGH; OVKNAHKQGH = 4501; if (OVKNAHKQGH) { if (31760 > 16539) { short RLTXWGZHYR; short GEOBYOKLES; } long long XHZSTOCISZ; XHZSTOCISZ = 22954; if (29408 > 21905) { bool JHYTHTGDKJ; } short RAXAIPWLJW; RAXAIPWLJW = 6467; if (RAXAIPWLJW) { long long ZGOYUWAYZD; } } long long EIPPCNMEQF; EIPPCNMEQF = 3644; short ZYDUAOZJRA; ZYDUAOZJRA = 632; if (ZYDUAOZJRA) { short PZAFKAOQXY; double SAAAUIOWLM; SAAAUIOWLM = 22279; if (SAAAUIOWLM) { short UFYBMKZBDF; short JYGBVNQHDC; } bool EFYYBKVPFD; EFYYBKVPFD = 10307; if (EFYYBKVPFD) { bool RQCXPYVCCR; bool CMCMTSPIFA; } if (30868 > 25897) { long long EWIHEWTHXS; double RDUMYFGMYW; } } } while (j >= 0 && s[j + 1] != s[i]) j = OZXICPQWDF[j]; bool RTAMEHWMGO; RTAMEHWMGO = 1477; OZXICPQWDF[i] = j + 1; if (19881 > 32092) { long long RIUVFDXUGO; if (13388 > 21570) { if (21487 > 7615) { short PSWIBTGZKN; } short XPOHUCUACK; XPOHUCUACK = 32156; if (XPOHUCUACK) { long long KZDFMDYGLZ; long long YRIRTLEODA; } bool BUKJIWBLIS; BUKJIWBLIS = 27616; if (BUKJIWBLIS) { short UIHOWHWHZP; } short ASQZFIRDXA; ASQZFIRDXA = 3309; } } if (s[i] == s[OZXICPQWDF[i - 1] + 1]) ODIUVNKJQW[i - 1] = ODIUVNKJQW[OZXICPQWDF[i - 1]]; else ODIUVNKJQW[i - 1] = OZXICPQWDF[i - 1]; if (27391 > 3744) { long long RSCAKDIEHL; RSCAKDIEHL = 11196; if (RSCAKDIEHL) { if (28157 > 27255) { double IWGDFKWLXD; bool VOMUPWPIND; } if (4100 > 11906) { bool QIXZLSKWDV; bool PLLNOGQRTF; } if (32712 > 11866) { short CZXRVBXXPU; short LASWUSAAMX; short JXQLYTDOKM; } } long long JGORDMHITJ; JGORDMHITJ = 16257; } j = i - 1; long long ZGLUSKXMSY; ZGLUSKXMSY = 21361; while (j >= 1) { if (s[j + 1] == s[i]) j = ODIUVNKJQW[j]; else { long long t = ask(i - j, i - 1); long long ZXXEWLUNJN; PASLQWKEND -= t, ZLMQOGHJFF[t]--, j = OZXICPQWDF[j]; if (26848 > 4959) { double ZIUPHCQHXF; long long ENGJOSZHOX; } } } long long add = (s[i] == s[1]); double BJDVQKKZOO; BJDVQKKZOO = 11772; while (ZLMQOGHJFF.size() && ((--ZLMQOGHJFF.end())->first) > w) { auto it = --ZLMQOGHJFF.end(); if (20559 > 3094) { long long VEQQVLIMKJ; VEQQVLIMKJ = 9639; if (15413 > 18844) { short DBCPWNWZKU; long long CBRMFIYLBH; } if (10465 > 8950) { long long QAVPKTSOLN; bool PIIKHCBCWK; } double NVGIGZTZQY; NVGIGZTZQY = 28060; if (NVGIGZTZQY) { double VGVNCHNPGM; short YRZQUOSJUM; } bool CPHJORRGJS; } add += it->second, PASLQWKEND -= it->second * it->first; if (11171 > 21467) { long long KRHUPMUQCT; KRHUPMUQCT = 4789; if (31245 > 5281) { long long CADVVAFLGJ; } } ZLMQOGHJFF.erase(it); long long YGIXFXONAK; YGIXFXONAK = 8967; } PASLQWKEND += add * w, ZLMQOGHJFF[w] += add; if (30861 > 32345) { long long MJHZOWCGQF; bool FJCOTOGVFN; FJCOTOGVFN = 13155; if (28712 > 12867) { if (27262 > 15580) { long long XRHQKNJWFK; bool WMWMAFDFVN; long long TSZBACQOUC; } if (8570 > 21638) { bool XLZICHFHVW; } short QGZZGTPGNW; QGZZGTPGNW = 32135; if (QGZZGTPGNW) { long long UJNORZHGWS; long long YTIXUOYAEX; bool YCXWDEQSDG; } long long MCPDAQXWVP; } } a26 = (a26 + PASLQWKEND) % 26, a30 = (a30 + PASLQWKEND) & Mask; long long KEDZHCKFIZ; KEDZHCKFIZ = 2329; if (KEDZHCKFIZ) { long long ZYURMHVIGM; } PASLQWKEND1 += PASLQWKEND; if (28120 > 8670) { bool THTEVDTHEQ; } if (PASLQWKEND1 >= inf) PASLQWKEND2++, PASLQWKEND1 -= inf; print(PASLQWKEND1, PASLQWKEND2); if (20512 > 5823) { if (4608 > 16596) { double YWDFXFBSAN; YWDFXFBSAN = 8542; if (YWDFXFBSAN) { short YKRCRINEMM; long long GRKAGLHJPR; long long YBGWHEWZXM; short SLGRSYCQMB; } if (17831 > 8044) { long long WSSQXKMEWI; } } bool WPHZJRTOXT; WPHZJRTOXT = 23409; long long ZVKRUTMJKO; ZVKRUTMJKO = 1981; } } return 0; long long ZUSFQYEYXO; ZUSFQYEYXO = 20994; if (ZUSFQYEYXO) { bool RTWAUOYVNL; long long SVOEZZDQBR; SVOEZZDQBR = 25293; double DHZACPREKX; DHZACPREKX = 25408; } }
|
#include <bits/stdc++.h> using namespace std; pair<long long, long long> p1[1005]; pair<long long, long long> p2[1005]; vector<long long> v; int main() { long long i, j, n, x, y, a, b; cin >> n; for (i = 0; i < n; i++) cin >> p1[i].first >> p1[i].second; for (i = 0; i < n; i++) cin >> p2[i].first >> p2[i].second; sort(p1, p1 + n); sort(p2, p2 + n); cout << p1[0].first + p2[n - 1].first << << p1[0].second + p2[n - 1].second; }
|
#include <bits/stdc++.h> using namespace std; long long inf = 2147483647; const long long ll = 9223372036854775807, ninf = 1000000000; const double eps = 1e-6; const long long nll = 1000000000000000000; vector<int> node[200005]; vector<int> num; int deg[200005] = {}; void dfs(int x) { for (int i = 0; i < node[x].size(); i++) { dfs(node[x][i]); } num.push_back(x); } int A[200005] = {}; int main() { int a; while (cin >> a) { int r = 1; for (int i = 1; i <= a; i++) { cin >> A[i]; deg[A[i]]++; if (A[i]) { deg[i]++; node[A[i]].push_back(i); } else { r = i; } } if (a % 2 == 0) { cout << NO << n ; continue; } dfs(r); vector<int> ans1, ans2; cout << YES << n ; for (int i = 0; i < num.size(); i++) { int now = num[i]; if (deg[now] % 2 == 0) { ans2.push_back(now); deg[A[now]]--; } else { ans1.push_back(now); } } for (int i = 0; i < ans2.size(); i++) { cout << ans2[i] << n ; } reverse(ans1.begin(), ans1.end()); for (int i = 0; i < ans1.size(); i++) { cout << ans1[i] << n ; } } return 0; }
|
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int fa[2][maxn << 1]; int cost[2][maxn][maxn]; int dd[2][maxn]; int n; int sz[2]; int dp[maxn]; void init(int t) { cin >> sz[t]; for (int i = (2); i <= (sz[t]); ++i) cin >> fa[t][i]; for (int i = (1); i <= (n); ++i) cin >> dd[t][i]; } void cal(int t) { for (int l = (1); l <= (n); ++l) { vector<int> sons(sz[t] + 1, 0); for (int i = (1); i <= (sz[t]); ++i) sons[fa[t][i]]++; for (int r = (l); r <= (n); ++r) { int now = dd[t][r]; int val = 0; while (now != 1 && sons[now] == 0) val++, sons[fa[t][now]]--, now = fa[t][now]; cost[t][l][r] = cost[t][l][r - 1] + val; } } } void solve() { for (int i = (1); i <= (n); ++i) { int& ans = dp[i]; for (int j = (0); j < (i); ++j) ans = max(ans, dp[j] + max(cost[1][j + 1][i], cost[0][j + 1][i])); } } int main(void) { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = (0); i < (2); ++i) init(i); for (int i = (0); i < (2); ++i) cal(i); solve(); cout << dp[n] << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; template <class T> inline T SQR(T x) { return x * x; } template <class T> inline string TOSTR(const T &x) { stringstream ss; ss << x; return ss.str(); } template <class T> void UPDATE_MIN(T &x, T y) { if (y < x) { x = y; } } template <class T> void UPDATE_MAX(T &x, T y) { if (x < y) { x = y; } } int gcd(int a, int b) { return a ? gcd(b % a, a) : b; } long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } long long powmod(long long a, long long p, long long m) { long long r = 1; while (p) { if (p & 1) r = r * a % m; p >>= 1; a = a * a % m; } return r; } const int MOD = 1000 * 1000 * 1000 + 7; const double PI = 3.1415926535897932384626433832795l; long long n, m, k; long long p10[10000]; long long p9_10[10000]; long long counts_a[100] = {}; long long counts_b[100] = {}; long long *counts, *counts2; int main() { cin >> n >> k >> m; long long a10 = 1, a9_10 = 1; for (int(i) = 0; (i) < (int)(n); (i)++) { p10[i] = a10; p9_10[i] = a9_10; a10 = (a10 * 10LL) % k; a9_10 = (a9_10 * ((i == 0) ? 9LL : 10LL)) % m; } counts = counts_a; counts2 = counts_b; counts[0] = 1; long long res = 0; for (int(i) = 0; (i) < (int)(n); (i)++) { for (int(j) = 0; (j) < (int)(k); (j)++) counts2[j] = 0; for (int(r) = 0; (r) < (int)(k); (r)++) { int mind = ((i == n) ? 1 : 0); for (int(d) = mind; (d) < (int)(10); (d)++) { long long r2 = (d * p10[i] + r) % k; counts2[r2] = (counts2[r2] + counts[r]) % m; } } res += (counts2[0] - 1) * p9_10[n - i - 1]; res %= m; while (res < 0) res += m; counts2[0] = 1; { __typeof(counts) tmp = counts; counts = counts2; counts2 = tmp; }; } cout << res << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; map<char, long long int> cou; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int n; cin >> n; while (n--) { string s; cin >> s; cou[s[0]]++; } long long int ans = 0; for (map<char, long long int>::iterator it = cou.begin(); it != cou.end(); it++) { long long int req = it->second; long long int f = (req + 1) / 2; long long int s = req / 2; ans = ans + (f * (f - 1)) / 2 + (s * (s - 1)) / 2; } cout << ans << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; int mark[1 << 22]; int is[1 << 22]; int a[1 << 22]; int n, m; int tot; void dfs(int x) { if (mark[x]) return; mark[x] = 1; if (is[x]) dfs(tot ^ x); for (int j = 0; j < n; j++) { if (x >> j & 1) { dfs(x ^ (1 << j)); } } } signed main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %d , &a[i]); is[a[i]] = 1; } tot = (1 << n) - 1; int ans = 0; for (int i = 1; i <= m; i++) { if (mark[a[i]]) continue; mark[a[i]] = 1; ans++; dfs(tot ^ a[i]); } printf( %d n , ans); return 0; }
|
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 7; const long long INF = 1e17 + 7; long long h[N], t[N], f[N][2], pos[N], w[N]; long long n, num = 0; struct edge { long long v, next; } e[N * 2]; struct pir { long long a, b; } p[N]; bool cmp(pir x, pir y) { return (x.b - x.a) < (y.b - y.a); } void add(long long x, long long y) { e[num] = (edge){y, pos[x]}; pos[x] = num++; } void dfs(long long x, long long fa) { long long cnt = 0, s1 = 0, s0 = 0, hh = 0, ss = 0; for (long long i = pos[x]; ~i; i = e[i].next) { if (e[i].v == fa) continue; hh = 1; dfs(e[i].v, x); if (h[e[i].v] > h[x]) s1++, ss += f[e[i].v][1]; if (h[e[i].v] < h[x]) s0++, ss += f[e[i].v][0]; } if (!hh) { f[x][0] = f[x][1] = t[x]; return; } w[0] = 0; for (long long i = pos[x]; ~i; i = e[i].next) { if (e[i].v != fa && h[e[i].v] == h[x]) { w[0] += f[e[i].v][0]; p[++cnt] = (pir){f[e[i].v][0], f[e[i].v][1]}; } } sort(p + 1, p + cnt + 1, cmp); for (long long i = 1; i <= cnt; i++) w[i] = w[i - 1] + p[i].b - p[i].a; f[x][0] = f[x][1] = INF; for (long long i = 0; i <= cnt + 1 - 1; i++) { f[x][0] = min(f[x][0], w[i] + max(cnt - i + s0, i + s1 + (x != 1)) * t[x] + ss); f[x][1] = min(f[x][1], w[i] + max(cnt - i + s0 + (x != 1), i + s1) * t[x] + ss); } } int main() { scanf( %I64d , &n); memset(pos, -1, sizeof(pos)); for (long long i = 1; i <= n; i++) scanf( %I64d , &t[i]); for (long long i = 1; i <= n; i++) scanf( %I64d , &h[i]); for (long long i = 1; i <= n - 1; i++) { long long x, y; scanf( %I64d%I64d , &x, &y); add(x, y); add(y, x); } dfs(1, 0); printf( %I64d n , f[1][0]); return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int i = 0; ios_base::sync_with_stdio(false); cin.tie(NULL); vector<int> ans; int n; int m; cin >> n >> m; int a[110]; int b[20]; memset(a, 0, sizeof a); memset(b, 0, sizeof b); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { int t; cin >> t; b[t] = 1; } for (int i = 0; i < n; i++) { if (b[a[i]] == 1) ans.push_back(a[i]); } for (int i = 0; i < ans.size(); i++) { cout << ans[i] << ; } return 0; }
|
#include <bits/stdc++.h> using namespace std; string t(int a) { int i, tmp = 1; for (i = 1; i <= a; i *= 3) { } string s; for (; i >= 1; i /= 3) { if (a / i == 2) s += 2 , a %= i; else if (a / i == 1) s += 1 , a %= i; else s += 0 ; } return s; } int main() { int i, a, b = 0, c; cin >> a >> c; string s1, s2, s3; s1 = t(a), s2 = t(c); int t = max(((int)s1.size()), ((int)s2.size())); for (i = 0; i < t; i++) { if (((int)s1.size()) - t + i >= 0) a = s1[((int)s1.size()) - t + i] - 0 ; else a = 0; if (((int)s2.size()) - t + i >= 0) c = s2[((int)s2.size()) - t + i] - 0 ; else c = 0; s3 += ((c - a + 3) % 3 + 0 ); } reverse(s3.begin(), s3.end()); for (i = 0; i < ((int)s3.size()); i++) { t = 1; for (int j = 0; j < i; j++) t *= 3; b += (s3[i] - 0 ) * t; } cout << b << endl; }
|
#include <bits/stdc++.h> using namespace std; long long n, m, vet[202020], cap[202020]; set<long long> s; int main() { scanf( %lld , &n); for (long long i = 1; i <= n; i++) scanf( %lld , &cap[i]), s.insert(i); scanf( %lld , &m); long long op, x, p, k; while (m--) { scanf( %lld , &op); if (op == 1) { scanf( %lld %lld , &p, &x); for (auto it = s.lower_bound(p); it != s.end() && x; it = s.erase(it)) { long long id = *it; if (cap[id] - vet[id] > x) { vet[id] += x; break; } x -= cap[id] - vet[id]; vet[id] = cap[id]; } } else { scanf( %lld , &k); printf( %lld n , vet[k]); } } }
|
#include <bits/stdc++.h> using namespace std; const int maxn = 15, maxx = 10; long long a[maxn], b[maxn], c[maxn]; void Init() { for (int i = 1; i <= maxx; i++) { long long x = i, l = 1, r = 0; while (x--) l *= 10, r = r * 10 + 9; l /= 10; a[i] = (r - l + 1) * i; b[i] = b[i - 1] + a[i]; c[i] = c[i - 1] + (b[i - 1] + i + b[i]) * (r - l + 1) / 2; } } int main() { ios::sync_with_stdio(0); Init(); long long t, n, pos; cin >> t; while (t--) { cin >> n; pos = lower_bound(c + 1, c + maxx + 1, n) - c; n = n - c[pos - 1]; long long l = 1, r = 0, x = pos, t = b[pos - 1]; while (x--) l *= 10, r = 10 * r + 9; l /= 10; long long L = l; while (l <= r) { long long mid = (l + r) >> 1; long long cnt = mid - L + 1; if ((2 * t + pos + cnt * pos) * cnt / 2 >= n) r = mid - 1; else l = mid + 1; } long long cnt = l - L; n -= (2 * t + pos + cnt * pos) * cnt / 2; pos = lower_bound(b + 1, b + maxx + 1, n) - b; n -= b[pos - 1]; int ans = 1; for (int i = 1; i < pos; i++) ans *= 10; t = (n - 1) / pos; n -= t * pos; ans += t; n = pos - n; while (n--) ans /= 10; cout << ans % 10 << endl; } return 0; }
|
#include <bits/stdc++.h> using namespace std; bool flag; int n, a[1010], vis[2010], T; pair<int, int> ans[5]; void read(int &x) { char ch = getchar(); int mark = 1; for (; ch != - && (ch < 0 || ch > 9 ); ch = getchar()) ; if (ch == - ) mark = -1, ch = getchar(); for (x = 0; ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - 48; x *= mark; } bool check(int step) { for (int i = 1; i <= n; i++) if (a[i] != i) return 0; return 1; } void rev(int *a, int l, int r) { for (int i = 0; i <= (r - l - 1) / 2; i++) swap(a[i + l], a[r - i]); } int expect() { int ans = 1; for (int i = 2; i <= n; i++) if (abs(a[i] - a[i - 1]) != 1) ans++; return ans; } void dfs(int step) { if (check(step - 1)) { printf( %d n , step - 1); for (int i = step - 1; i; i--) printf( %d %d n , ans[i].first, ans[i].second); flag = 1; return; } if (step > 3) return; int c[1010]; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) if (abs(a[i - 1] - a[j]) == 1 || abs(a[i] - a[j + 1]) == 1) { for (int k = i; k <= j; k++) c[k] = a[k]; rev(a, i, j); if (expect() <= (3 - step) * 2 + 1) { ans[step] = make_pair(i, j); dfs(step + 1); if (flag) return; } for (int k = i; k <= j; k++) a[k] = c[k]; } } } int main() { read(n); for (int i = 1; i <= n; i++) read(a[i]); a[n + 1] = n + 1; dfs(1); return 0; }
|
#include <bits/stdc++.h> using namespace std; bool test(long long k, long long x, long long n, long long m, long long p1, long long l1, long long r1, long long p2, long long l2, long long r2) { if (p1 * 2 + l1 + r1 > n) return false; if (p2 * 2 + l2 + r2 > m) return false; for (long long i = 0; i < k - 2; i++) { long long p3 = p1 + p2 + (r1 * l2); long long l3 = l1; long long r3 = r2; l1 = l2; r1 = r2; p1 = p2; l2 = l3; r2 = r3; p2 = p3; if (p2 > x) return false; } return p2 == x; } string build(long long n, long long p, long long l, long long r) { string s(n, X ); if (l) s[0] = C ; if (r) s[n - 1] = A ; for (long long i = 0; i < p; i++) { s[l + i * 2] = A ; s[l + i * 2 + 1] = C ; } return s; } signed main() { ios::sync_with_stdio(false); long long k, x, n, m; cin >> k >> x >> n >> m; for (long long p1 = 0; p1 <= n / 2; p1++) { for (long long l1 = 0; l1 <= 1; l1++) { for (long long r1 = 0; r1 <= 1; r1++) { for (long long p2 = 0; p2 <= m / 2; p2++) { for (long long l2 = 0; l2 <= 1; l2++) { for (long long r2 = 0; r2 <= 1; r2++) { if (test(k, x, n, m, p1, l1, r1, p2, l2, r2)) { string s1 = build(n, p1, l1, r1); string s2 = build(m, p2, l2, r2); cout << s1 << n << s2 << n ; return 0; } } } } } } } cout << Happy new year! n ; return 0; }
|
#include <bits/stdc++.h> #pragma GCC optimize 2 using namespace std; const int N = 2e4 + 9; struct stree { int l, r, lazy, sum; } t[N << 2]; int dp[20005]; inline void pushdown(int now) { int lazy = t[now].lazy; if (!lazy) return; if (t[now].l != t[now].r) t[now * 2].lazy += lazy, t[now * 2 + 1].lazy += lazy; t[now].sum += lazy; t[now].lazy = 0; } inline void build(int now, int l, int r) { t[now].l = l, t[now].r = r, t[now].lazy = 0; if (l == r) { t[now].sum = dp[l]; return; } int mid = (l + r) / 2; build(now * 2, l, mid), build(now * 2 + 1, mid + 1, r); t[now].sum = max(t[now * 2].sum, t[now * 2 + 1].sum); } inline void change(int now, int l, int r, int d) { if (l > r) return; pushdown(now); if (t[now].l == l && t[now].r == r) { t[now].lazy += d; return; } pushdown(now); if (t[now * 2].r >= r) change(now * 2, l, r, d); else if (t[now * 2 + 1].l <= l) change(now * 2 + 1, l, r, d); else change(now * 2, l, t[now * 2].r, d), change(now * 2 + 1, t[now * 2 + 1].l, r, d); pushdown(now); if (t[now].l != t[now].r) pushdown(now * 2), pushdown(now * 2 + 1), t[now].sum = max(t[now * 2].sum, t[now * 2 + 1].sum); } inline int query(int now, int l, int r) { pushdown(now); if (l > r) return 0; if (t[now].l == l && t[now].r == r) return t[now].sum; if (t[now * 2].r >= r) return query(now * 2, l, r); else if (t[now * 2 + 1].l <= l) return query(now * 2 + 1, l, r); else return max(query(now * 2, l, t[now * 2].r), query(now * 2 + 1, t[now * 2 + 1].l, r)); } int qzh[55][20005], a[55][20005], cf[20005]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; qzh[i][j] = qzh[i][j - 1] + a[i][j]; } } int ans = 0; for (int i = 1; i <= n; i++) { if (i != 1) { for (int j = 1; j <= k; j++) dp[j] -= qzh[i][k] - qzh[i][j - 1]; } build(1, 1, m); memset(dp, 0, sizeof dp); for (int j = 1; j <= m - k + 1; j++) { dp[j] = query(1, 1, m) - qzh[i][j - 1] - qzh[i + 1][j - 1] + qzh[i][j + k - 1] + qzh[i + 1][j + k - 1]; if (i != 1) change(1, max(1, j - k + 1), min(m, j), a[i][j]), change(1, max(1, j + 1), min(m, j + k), -a[i][j + k]); ans = max(ans, dp[j]); } } cout << ans; return 0; }
|
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-6; template <class T> T gcd(T a, T b) { if (!b) return a; return gcd(b, a % b); } const int maxn = 1e6 + 10; int n, m; int phi[maxn]; int a[maxn]; int get(int x) { int res = x; for (long long i = 2; i * i <= x; i++) { if (x % i == 0) { res = res / i * (i - 1); while (x % i == 0) x /= i; } } if (x > 1) res = res / x * (x - 1); return res; } int qpow(int b, int n, int mod) { int res = 1; while (n) { if (n & 1) res = 1LL * res * b >= mod ? 1LL * res * b % mod + mod : res * b; b = 1LL * b * b >= mod ? 1LL * b * b % mod + mod : b * b; n >>= 1; } return res; } int solve(int l, int r, int k) { if (phi[k] == 1) return 1; if (l == r) { if (a[l] < phi[k]) return a[l]; else return a[l] % phi[k] + phi[k]; } else return qpow(a[l], solve(l + 1, r, k + 1), phi[k]); } int main() { scanf( %d , &n); scanf( %d , &phi[0]); while (phi[m] != 1) { phi[m + 1] = get(phi[m]); m++; } for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } int q; scanf( %d , &q); for (int i = 0; i < q; i++) { int l, r; scanf( %d , &l); scanf( %d , &r); int ans = solve(l, r, 0) % phi[0]; printf( %d n , ans); } return 0; }
|
#include <bits/stdc++.h> using namespace std; long long M = 1000000007; long long bigMod(long long n, long long power, long long mod = M) { if (power == 0) return 1; if (power == 1) return n % mod; else if (power % 2 == 0) { long long v = bigMod(n, power / 2, mod); return ((v % mod) * (v % mod)) % mod; } else { long long v = bigMod(n, power - 1, mod) % mod; return ((v % mod) * (n % mod)) % mod; } } int main() { long long n; scanf( %lld , &n); long long number = bigMod(2, n); cout << ((number * (number + 1)) / 2) % M << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; const int N = 3005; int n, a[N]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d , a + i); } int ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) { if (a[j] > a[i]) { ++ans; } } } printf( %.12f n , (double)(ans / 2 * 4 + ans % 2)); return 0; }
|
#include <bits/stdc++.h> using namespace std; int n, K; int pover[64000]; int ipover[64000]; int dt[503][503]; int lsum[2][503][503]; const int mod = 1000000007; int main() { scanf( %d%d , &n, &K); int maxval = 0; pover[0] = 1; for (int i = 1; i < 64000; i++) { pover[i] = (pover[i - 1] * (long long)2) % mod; } ipover[0] = 1; for (int i = 1; i < 64000; i++) { ipover[i] = (ipover[i - 1] * (long long)500000004) % mod; } for (int j = 0; j <= 0; j++) { dt[0][j] = 1; } for (int k = 0; k <= n; k++) { long long ksum = 0; for (int j = 0; j < k; j++) { long long mul = pover[(k - j) * (n - k + 1)]; ksum = (ksum + dt[0][j] * mul) % mod; lsum[1][j][k] = ksum; } } for (int i = 1; i <= K; i++) { int ci = i % 2; for (int j = 1; j <= n; j++) { for (int k = 1; k <= j; k++) { long long baseCnt = lsum[ci][k - 1][j]; long long tot = baseCnt * ipover[j - k + 1] % mod; dt[i][j] = (dt[i][j] + tot) % mod; } } int ni = 1 - i % 2; memset(lsum[ni], 0, sizeof(lsum[0])); for (int k = 0; k <= n; k++) { long long ksum = 0; for (int j = 0; j < k; j++) { long long mul = pover[(k - j) * (n - k + 1)]; ksum = (ksum + dt[i][j] * mul) % mod; lsum[ni][j][k] = ksum; } } } long long ans = 0; for (int i = 0; i <= n; i++) { ans += dt[K][i]; ans %= mod; } ans %= mod; printf( %d n , (int)ans); return 0; }
|
#include <bits/stdc++.h> using namespace std; int d[1005], s[1005], sufmax[1005], mxpos[1005], pred[1005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; ++n; for (int i = 1; i < n; ++i) cin >> d[i]; for (int i = 1; i < n; ++i) cin >> s[i]; for (int i = n - 1; i >= 1; --i) { if (s[i] > sufmax[i + 1]) { mxpos[i] = i; sufmax[i] = s[i]; } else { mxpos[i] = mxpos[i + 1]; sufmax[i] = sufmax[i + 1]; } } for (int i = 1; i < n; ++i) pred[i] = pred[i - 1] + d[i]; int tott = 0, oil = s[1]; for (int i = 1; i < n;) { int j = i; do { oil -= d[j]; ++j; while (oil < 0) tott += k, oil += s[i]; oil += s[j]; } while (s[j] < s[i] && j < n); i = j; } cout << tott + pred[n - 1] << endl; }
|
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10, B = 1e6 + 3; int n, m, p1[N][2], p2[N][2], x, y; long long ans = 1; int main() { scanf( %d%d n , &n, &m); char a[n + 3][m + 3]; for (int i = 0; i < n; ++i) gets(a[i]); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) if (a[i][j] != . ) { x = (a[i][j] < 2 ) || (a[i][j] > 3 ); y = i % 2; p1[j][x ^ y] = 1; x = a[i][j] < 3 ; y = j % 2; p2[i][x ^ y] = 1; } } for (int i = 0; i < m; ++i) ans = (ans * (2 - p1[i][0] - p1[i][1])) % B; for (int i = 0; i < n; ++i) ans = (ans * (2 - p2[i][0] - p2[i][1])) % B; printf( %lld n , ans); return 0; }
|
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3 ) #pragma GCC target( avx,avx2,sse,sse2,sse3,sse4,popcnt,fma ) #pragma GCC optimize( unroll-loops ) const long long int MAXN = 2e5 + 5; const long long int mod = 1000000007; const long long int N = 200005; void solve() { map<pair<int, int>, vector<int>> mpX, mpY; int n, m, k; cin >> n >> m >> k; vector<int> xec(n), yec(m); map<int, int> haveX, haveY; for (int i = 0; i < n; i++) { cin >> xec[i], haveX[xec[i]] += 1; } for (int i = 0; i < m; i++) { cin >> yec[i], haveY[yec[i]] += 1; } for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; if (haveX[x] && haveY[y]) continue; if (haveX[x]) { int idx = lower_bound(yec.begin(), yec.end(), y) - yec.begin(); mpX[{yec[idx - 1], yec[idx]}].push_back(x); } if (haveY[y]) { int idx = lower_bound(xec.begin(), xec.end(), x) - xec.begin(); mpY[{xec[idx - 1], xec[idx]}].push_back(y); } } long long int ans = 0; for (auto [a, b] : mpX) { sort(b.begin(), b.end()); map<int, int> mpTemp; int total = b.size(); for (auto x : b) { mpTemp[x] += 1; } for (auto [c, d] : mpTemp) { ans += (long long int)d * (long long int)(total - d); } } for (auto [a, b] : mpY) { sort(b.begin(), b.end()); map<int, int> mpTemp; int total = b.size(); for (auto y : b) { mpTemp[y] += 1; } for (auto [c, d] : mpTemp) { ans += (long long int)d * (long long int)(total - d); } } cout << ans / 2ll << n ; return; } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; while (t--) { solve(); } return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, c0, c1, h; cin >> n >> c0 >> c1 >> h; string s; cin >> s; int o = 0, z = 0; for (int i = 0; i < n; i++) { if (s[i] == 1 ) o++; else z++; } int ans = 0; if (c0 < c1) { if (c0 + h <= c1) ans = z * c0 + o * (c0 + h); else ans = z * c0 + o * c1; } else { if (c1 + h <= c0) ans = c1 * o + z * (c1 + h); else ans = c1 * o + c0 * z; } cout << ans << endl; } return 0; }
|
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( O3 ) #pragma GCC optimize( O2 ) #pragma GCC optimize( inline ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; const int INF = 1e9 + 7; int n; vector<int> G[55]; double dp[55][55][55][55]; int vis[55][55]; double tmp[55][55]; long long C[55][55]; double cpro[55][55][55][55]; void merge_dp(int asz, double a[][55], int bsz, double b[][55], double ret[][55]) { for (int i = 0; i <= asz + bsz; i++) for (int j = 0; j <= asz + bsz; j++) ret[i][j] = 0; for (int ia = 0; ia <= asz; ia++) for (int ja = 0; ja <= asz; ja++) for (int ib = 0; ib <= bsz; ib++) for (int jb = 0; jb <= bsz; jb++) { if (ia == 0 && ib == 0) { ret[ia + ib][0] = a[ia][0] * b[ib][0]; continue; } for (int jt = ja + jb; jt <= asz + bsz; jt++) ret[ia + ib][jt] += a[ia][ja] * b[ib][jb] * (cpro[jt][ja][asz][bsz] + cpro[jt][jb][bsz][asz]) / C[asz + bsz][asz]; } } int dfs(int v, int par) { if (vis[v][par]) return vis[v][par]; int tsz = 0; dp[v][par][0][0] = 1.0; for (int i = 0; i < (int)(G[v].size()); i++) { int u = G[v][i]; if (u == par) continue; int csz = dfs(u, v); merge_dp(tsz, dp[v][par], csz, dp[u][v], tmp); tsz += csz; for (int j = 0; j <= tsz; j++) for (int k = 0; k <= tsz; k++) dp[v][par][j][k] = tmp[j][k]; } if (par > 0) { for (int i = 0; i <= tsz; i++) for (int j = 0; j <= tsz; j++) { tmp[i][j] = dp[v][par][i][j]; dp[v][par][i][j] *= 1 - 1.0 * j / (tsz + 1); } for (int i = 0; i <= tsz; i++) for (int j = 0; j <= tsz; j++) for (int k = j; k <= tsz; k++) dp[v][par][i + 1][k + 1] += tmp[i][j] * (1.0 / (tsz + 1)); tsz++; } return vis[v][par] = tsz; } double aa[55]; double gen_ans(int v) { dfs(v, 0); memset(aa, 0, sizeof(aa)); for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) aa[i] += dp[v][0][i][j]; for (int i = n; i >= 0; i--) for (int j = n; j > i; j--) aa[i] -= C[j][i] * aa[j]; double ret = 0.0, t = 1.0; for (int i = 0; i <= n; i++) { ret = ret + aa[i] * t; t *= 0.5; } return ret; } void init_C() { C[0][0] = 1; for (int i = 1; i <= (int)(n); i++) { C[i][0] = 1; for (int j = 1; j <= (int)(n); j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; } for (int a = 0; a <= n; a++) for (int b = 0; a + b <= n; b++) for (int ja = 0; ja <= a; ja++) for (int jt = ja; jt <= a + b; jt++) if (ja > 0) cpro[jt][ja][a][b] = C[jt - 1][ja - 1] * C[a + b - jt][a - ja]; else cpro[jt][ja][a][b] = 0; } int main() { scanf( %d , &n); init_C(); for (int i = 0; i < (int)(n - 1); i++) { int u, v; scanf( %d%d , &u, &v); G[u].push_back(v); G[v].push_back(u); } for (int i = 1; i <= (int)(n); i++) printf( %.8lf n , gen_ans(i)); return 0; }
|
#include <bits/stdc++.h> using namespace std; const int maxn = 500010; int m, k, n, s, a[maxn], b[maxn], c[maxn], maxx, tong[maxn], ansl, ansr, vis[maxn]; bool check(int l, int r) { memcpy(c, tong, sizeof(c)); for (int i = l; i <= r; i++) c[a[i]]--; for (int i = 1; i <= maxx; i++) if (c[i] > 0) { return false; } return true; } void gen(int l, int r) { int temp = l - (min(n - 1, (l - 1) / k) * k + 1); temp += max(0, r - l + 1 - k); if (temp <= m - n * k) { printf( %d n , temp); int num = 0; for (int i = min(n - 1, (l - 1) / k) * k + 1; i < l; i++) { printf( %d , i); num++; } int num2 = 0; memset(c, 0, sizeof(c)); for (int i = l; i <= r; i++) if (c[a[i]] + 1 <= tong[a[i]]) { vis[i] = 1; c[a[i]]++; num2++; } num2 = r - l + 1 - num2; num += num2; for (int i = l; i <= r; i++) if (!vis[i] && num > temp) { num--; vis[i] = 1; } for (int i = l; i <= r; i++) if (!vis[i]) printf( %d , i); exit(0); } } void solve(int x) { memset(c, 0, sizeof(c)); int cur = m; for (int i = x; i <= m; i++) c[a[i]]++; for (int i = x - 1; i >= 1; i--) { c[a[i]]++; while (cur > i) { if (c[a[cur]] - 1 >= tong[a[cur]] && c[a[cur - 1]] + 1 >= tong[a[cur - 1]]) { c[a[cur]]--; cur--; } else break; } gen(i, cur); } } int main() { scanf( %d%d%d%d , &m, &k, &n, &s); for (int i = 1; i <= m; i++) scanf( %d , &a[i]); for (int i = 1; i <= s; i++) { scanf( %d , &b[i]); maxx = max(maxx, b[i]); tong[b[i]]++; } int l = 1, r = m, res = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid, m)) { res = mid; l = mid + 1; } else r = mid - 1; } if (res) { gen(res, m); solve(res); puts( -1 ); } else puts( -1 ); return 0; }
|
#include <bits/stdc++.h> using namespace std; const int N = 2005; bool can = 1; char arr[N][N]; int n, m, vis[N][N], dp[N][N]; bool valid(pair<int, int> a) { return min(a.first, a.second) > -1 && a.first < n && a.second < m && arr[a.first][a.second] != # ; } pair<int, int> get_next(pair<int, int> a) { if (arr[a.first][a.second] == < ) return {a.first, a.second - 1}; if (arr[a.first][a.second] == > ) return {a.first, a.second + 1}; if (arr[a.first][a.second] == ^ ) return {a.first - 1, a.second}; return {a.first + 1, a.second}; } void dfs(pair<int, int> u) { vis[u.first][u.second] = 1; pair<int, int> c = get_next(u); if (valid(c)) { if (vis[c.first][c.second] == 0) dfs(c); else if (vis[c.first][c.second] == 1) { can = 0; return; } } vis[u.first][u.second] = 2; } bool go(pair<int, int> u) { vis[u.first][u.second] = 1; pair<int, int> c = get_next(u); bool ret = 1; if (valid(c)) { if (vis[c.first][c.second] == 0) ret &= go(c); else ret = 0; } return ret; } int solve(pair<int, int> u) { if (!valid(u)) return 0; if (~dp[u.first][u.second]) return dp[u.first][u.second]; pair<int, int> c = get_next(u); return dp[u.first][u.second] = solve(c) + 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> arr[i][j]; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) if (!vis[i][j] && valid({i, j})) dfs({i, j}); if (can) { vector<pair<int, pair<int, int>>> v; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) v.push_back({solve({i, j}), {i, j}}); sort(v.rbegin(), v.rend()); if (v.size() == 1 || v[0].first == 0) cout << v[0].first; else { int ans1 = v[0].first, ans2 = v[0].first - 1; memset(vis, 0, sizeof(vis)); go(v[0].second); for (int i = 1; i < v.size(); ++i) { if (v[i].first < v[i - 1].first) break; if (go(v[i].second)) { ans2 = ans1; break; } } cout << ans1 + ans2; } } else cout << -1; return 0; }
|
#include <bits/stdc++.h> using namespace std; const int inf = 1.01e9; const double eps = 1e-9; const int N = 1e5 + 10; int t[N]; int mem[N]; int main() { int n; scanf( %d , &n); for (int i = 0; (i) < (n); ++i) scanf( %d , &t[i]); int s = 0; for (int i = 0; (i) < (n); ++i) { int v = s + 20; if (i) { int l = lower_bound(t, t + i, t[i] - 90 + 1) - t; v = min(v, mem[l] + 50); } if (i) { int l = lower_bound(t, t + i, t[i] - 1440 + 1) - t; v = min(v, mem[l] + 120); } mem[i + 1] = v; printf( %d n , v - s); s = v; } return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int x, y; scanf( %d %d , &x, &y); long long ans = 0; for (int val = 1; val <= x; ++val) { ans += (int)floor((y - (5 - (val % 5))) / 5.0) + 1; } cout << ans << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; const long double PI = 3.14159265359; const long long MOD = (long long)1e9 + 7; const long long MAXN = (long long)1e5 + 10; const long long INF = (long long)9223372036854775; const long double EPS = (long double)1e-8; long long par[MAXN], sz[MAXN], ln[MAXN], pw[MAXN]; pair<pair<long long, long long>, long long> a[MAXN]; long long get_par(long long node) { if (node == par[node]) return node; par[node] = get_par(par[node]); return par[node]; } void merge(long long a, long long b) { long long x = get_par(a); long long y = get_par(b); if (x == y) return; ln[y] += ln[x]; sz[y] += sz[x]; par[x] = y; } bool CMPx(pair<pair<long long, long long>, long long> a, pair<pair<long long, long long>, long long> b) { return a.first.first < b.first.first; } bool CMPy(pair<pair<long long, long long>, long long> a, pair<pair<long long, long long>, long long> b) { return a.first.second < b.first.second; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (int i = 0; i < MAXN; i++) par[i] = i; pw[0] = 1; for (int i = 1; i < MAXN; i++) pw[i] = (pw[i - 1] * 2ll) % MOD; fill(sz, sz + MAXN, 1); long long n; scanf( %lld , &n); for (int i = 0; i < n; i++) { scanf( %lld%lld , &a[i].first.first, &a[i].first.second); a[i].second = i; } sort(a, a + n, CMPx); ln[get_par(a[0].second)]++; for (int i = 1; i < n; i++) { if (a[i].first.first == a[i - 1].first.first) { merge(a[i].second, a[i - 1].second); } else { ln[get_par(a[i].second)]++; } } sort(a, a + n, CMPy); ln[get_par(a[0].second)]++; for (int i = 1; i < n; i++) { if (a[i].first.second == a[i - 1].first.second) { merge(a[i].second, a[i - 1].second); } else { ln[get_par(a[i].second)]++; } } long long ans = 1; for (int i = 0; i < n; i++) { if (par[i] == i) { if (ln[i] <= sz[i]) { ans *= pw[ln[i]]; } else { ans *= (pw[ln[i]] - 1); } ans %= MOD; } } printf( %lld , ans); return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int n, l = 0; char a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (a - 0 == 1) l++; else l--; } cout << abs(l); return 0; }
|
#include <bits/stdc++.h> using namespace std; long long offset[1000]; vector<pair<long long, int> > x[1000]; long long v[500005]; int bucketsize = 700; inline int bucket(int x) { return x / bucketsize; } int buckets, n; inline int bstart(int x) { if (x == buckets + 1) { return n + 1; } return x * bucketsize; } void resort(int buc) { x[buc].clear(); int l = bstart(buc), r = bstart(buc + 1); for (int j = l; j < r; j++) { x[buc].push_back({v[j], j}); } sort(x[buc].begin(), x[buc].end()); } int main() { int q; scanf( %d %d , &n, &q); buckets = bucket(n); for (int i = 1; i <= n; i++) { int k; scanf( %d , &k); v[i] = k; x[bucket(i)].push_back({v[i], i}); } for (int i = 0; i <= buckets; i++) { resort(i); } for (int qq = 0; qq < q; qq++) { int t; scanf( %d , &t); if (t == 1) { int l, r, dd; scanf( %d %d %d , &l, &r, &dd); long long d = dd; int lbucket0 = bucket(l); int lbucket1 = lbucket0 + 1; int rbucket = bucket(r); int lstart1 = bstart(lbucket1); for (int j = lbucket1; j < rbucket; j++) { offset[j] += d; } if (lbucket0 == rbucket) { for (int j = l; j <= r; j++) v[j] += d; resort(lbucket0); } else { for (int j = l; j < lstart1; j++) v[j] += d; for (int j = bstart(rbucket); j <= r; j++) v[j] += d; resort(lbucket0); resort(rbucket); } } else { int yy; scanf( %d , &yy); long long y = yy; vector<pair<long long, int> >::iterator it; int l = 0, r = -1; for (int i = 0; i <= buckets; i++) { if (y - offset[i] <= 0) continue; pair<long long, int> search = {y - offset[i], 0}; it = lower_bound(x[i].begin(), x[i].end(), search); if (it == x[i].end()) continue; if (it->first == y - offset[i]) { l = it->second; break; } } for (int i = buckets; i >= 0; i--) { if (y - offset[i] <= 0) continue; pair<long long, int> search = {y - offset[i] + 1, 0}; it = lower_bound(x[i].begin(), x[i].end(), search); if (it == x[i].begin()) continue; it--; if (it->first == y - offset[i]) { r = it->second; break; } } printf( %d n , r - l); } } return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int a, b, n; cin >> a >> b >> n; if (n % 3 == 0) cout << a << endl; else if (n % 3 == 1) cout << b << endl; else cout << (a ^ b) << endl; } }
|
#include <bits/stdc++.h> using namespace std; int n, m, a; int tab[105]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a; tab[a]--; } sort(tab + 1, tab + 1 + 100); {} for (int wynik = 1; wynik <= 101; wynik++) { int ile = 0; for (int i = 1; i <= 100; i++) { ile += (-tab[i]) / wynik; } if (ile < n) { printf( %d n , wynik - 1); return 0; } } puts( 0 ); return 0; }
|
#include <bits/stdc++.h> namespace myland { using namespace std; namespace _abbr { const double EPS(1e-8); const double PI(acos(-1.0)); const int INF(0x3f3f3f3f); const long long INFL(0x3f3f3f3f3f3f3f3fll); const int MOD(1e9 + 7); } // namespace _abbr using namespace _abbr; namespace _solve {} using namespace _solve; namespace _calculate { bool odd(long long x) { return x & 1; } bool even(long long x) { return (x & 1) ^ 1; } bool posi(long long x) { return x > 0; } bool nega(long long x) { return x < 0; } bool zero(long long x) { return x == 0; } bool prime(long long x) { if (x < 2) return 0; for (int i = 2; i * i <= x; i++) if (x % i == 0) return 0; return 1; } long long droot(long long x) { return 1 + (x - 1) % 9; } long long upd(long long a, long long b) { return a % b ? a / b + 1 : a / b; }; long long random(long long a, long long b) { return a + rand() * rand() % (b - a + 1); }; long long bitn(long long x) { long long c = 0; while (x) c++, x >>= 1; return c; } template <class T> T sqr(T x) { return x * x; } long long qpow(long long a, long long n, long long mod = MOD) { long long res(1); while (n) { if (n & 1) (res *= a) %= mod; (a *= a) %= mod; n >>= 1; } return res % mod; } template <class T> void tomin(T& a, T b) { if (b < a) a = b; } template <class T> void tomax(T& a, T b) { if (b > a) a = b; } } // namespace _calculate using namespace _calculate; namespace _simple_algo { long long stol(const string& s) { long long x = 0; for (char c : s) x = x * 10 + c - 48; return x; } string ltos(long long x) { string s = ; if (x == 0) return 0 ; while (x) s = char(x % 10 + 48) + s, x /= 10; return s; } bool pal(const string& s) { int l = s.size(); for (int i = 0, j = l - 1; i < j; i++, j--) if (s[i] != s[j]) return 0; return 1; } } // namespace _simple_algo using namespace _simple_algo; namespace _io { template <class T> void rd(T& x) { cin >> x; } long long rd() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x * f; } void rd(int& x) { x = rd(); } void rd(long long& x) { x = rd(); } template <class A, class B> void rd(A& a, B& b) { rd(a), rd(b); } template <class A, class B> void rd(pair<A, B>& p) { cin >> p.first >> p.second; } template <class T> void wt(const T& x) { cout << x << endl; } template <class T> void wt(const T& x, char c) { cout << x << c; } template <class T> void wt(const T& x, const string& s) { cout << x << s; } template <class T> void wt(const T& x, int rnd) { cout << fixed << setprecision(rnd) << x << endl; } template <class A, class B> void wt(const pair<A, B>& make_pair) { cout << make_pair.first << << make_pair.second << endl; } template <class T> void wt(const vector<T>& vec, int l, int r) { for (int i = l; i <= r; i++) cout << vec[i] << ; cout << endl; } } // namespace _io using namespace _io; } // namespace myland using namespace myland; const int N(2e5 + 5); long long n, k; long long a[N], d[N]; int main() { rd(n, k); for (int i = 1; i <= n; i++) rd(a[i]), d[a[i] % k]++; long long ans(0); for (int i = 0; i <= k - 1; i++) { if (i == 0 || (k % 2 == 0 && i == k / 2)) { ans += d[i] / 2 * 2; continue; } long long t(min(d[i], d[k - i])); d[i] -= t; d[k - i] -= t; ans += 2 * t; } wt(ans); }
|
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, a[100001]; long long sum = 0, x = 0, ans = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i], sum += a[i]; sum = sum / n; for (int i = 0; i < n; i++) x += a[i] - sum, ans += abs(x); cout << ans; return 0; }
|
#include <bits/stdc++.h> using namespace std; int n; char a[440000], b[440000]; int cnta = 0, cntb = 0; int df[440000] = {0}; int czl[440000], czr[440000]; int zz1 = 0, zz2 = 0; int ab[440000] = {0}, ba[440000] = {0}; int ans = 0; int main() { cin >> n; cin >> a >> b; for (int i = 0; i < n; i++) { if (a[i] == a ) { cnta++; if (a[i] != b[i]) ab[++zz1] = i + 1; } if (b[i] == a ) { cntb++; if (a[i] != b[i]) ba[++zz2] = i + 1; } } if ((zz1 + zz2) % 2 == 1) { cout << -1 << endl; return 0; } while (zz1 || zz2) { if (zz2 % 2 == 1) { zz2++; ans++; czl[ans] = ab[zz1], czr[ans] = ab[zz1]; ba[zz2] = ab[zz1]; zz1--; } if (zz1) { ans++; czl[ans] = ab[zz1], czr[ans] = ab[zz1 - 1]; zz1 -= 2; } else { ans++; czl[ans] = ba[zz2], czr[ans] = ba[zz2 - 1]; zz2 -= 2; } } cout << ans << endl; for (int i = 1; i <= ans; i++) cout << czl[i] << << czr[i] << endl; return 0; }
|
#include <bits/stdc++.h> using namespace std; const int N = 1010; int vis[N]; vector<int> a[N], tmp; int main() { int n; scanf( %d , &n); int x = 1; for (int i = 2; i <= n; i++) { if (n - (n + i - 1) / i - i + 1 > n - (n + x - 1) / x - x + 1) x = i; } int ans = n - (n + x - 1) / x - x + 1; int cur = 0; for (int i = 1; i <= n; i++) { if (i % x == 1) cur++; a[cur].push_back(i); } int cnt = 0; while (cnt < ans) { for (int i = 1; i <= cur; i++) { int sz = a[i].size(); for (int j = 0; j < sz - 1; j++) { if (!vis[a[i][j]]) { vis[a[i][j]] = 1; tmp.push_back(a[i][j]); } if (tmp.size() == x) break; } if (tmp.size() == x) break; } int k = tmp.size(); cnt += k; printf( %d , k); for (int j : tmp) printf( %d , j); printf( n ); fflush(stdout); tmp.clear(); int pos; scanf( %d , &pos); for (int i = 1; i <= k; i++) { if (vis[pos]) cnt--; vis[pos] = 0; pos = pos % n + 1; } } printf( 0 n ); fflush(stdout); return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; bool a[m + 1]; memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) { int l, r; cin >> l >> r; for (int j = l; j <= r; j++) a[j] = 1; } vector<int> v; int res = 0; for (int i = 1; i <= m; i++) { if (a[i] == 0) { res++; v.push_back(i); } } cout << res << endl; for (int i = 0; i < v.size(); i++) cout << v[i] << ; }
|
#include <bits/stdc++.h> using namespace std; struct a1 { int value, freq; } arr[101]; bool compare(a1 lhs, a1 rhs) { return lhs.freq > rhs.freq; } int main() { int temp = 0, j, n, num = 0, m, i, a[101], ans = 0; scanf( %d %d , &n, &m); int b[n], c[n]; memset(a, 0, sizeof(a)); for (i = 0; i < n; i++) { scanf( %d , &temp); a[temp]++; } temp = 0; for (i = 1; i <= 100; i++) { if (a[i] != 0) { arr[num].freq = a[i]; arr[num++].value = i; } } sort(arr, arr + num, compare); for (i = 0; i < num; i++) { j = 0; while (j < arr[i].freq) { b[temp++] = arr[i].value; j++; } } for (i = arr[0].freq; i < n; i++) { c[i - arr[0].freq] = b[i]; } for (i = 0; i < arr[0].freq; i++) { c[n - arr[0].freq + i] = arr[0].value; } for (i = 0; i < n; i++) { if (b[i] != c[i]) ans++; } printf( %d n , ans); for (i = 0; i < n; i++) { printf( %d %d n , b[i], c[i]); } return 0; }
|
#include <bits/stdc++.h> using namespace std; template <class A> void pr(A a) { cout << a; cout << n ; } template <class A, class B> void pr(A a, B b) { cout << a << ; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << ; pr(b, c); } template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) { cout << a << ; pr(b, c, d); } template <class A> void PR(A a, long long n) { for (long long i = (long long)(0); i < (long long)(n); i++) { if (i) cout << ; cout << a[i]; } cout << n ; } long long check(long long n, long long m, long long x, long long y) { return x >= 0 && x < n && y >= 0 && y < m; } const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; void Main() { int h1, m1, h2, m2; scanf( %d:%d , &h1, &m1); scanf( %d:%d , &h2, &m2); int d = h1 * 60 + m1 + h2 * 60 + m2; d /= 2; if (h1 * 60 + m1 > h2 * 60 + m2) d += 12 * 60; d %= 24 * 60; printf( %02d:%02d n , d / 60, d % 60); } int main() { Main(); return 0; }
|
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct Node { int a, px, ori, c; } node[N]; int n, l, r; bool cmp_px(Node &a, Node &b) { return a.px < b.px; } bool cmp_ori(Node &a, Node &b) { return a.ori < b.ori; } int main() { cin >> n >> l >> r; int t; for (int i = 0; i < n; i++) { cin >> t; node[i].ori = i; node[i].a = t * (-1); node[i].c = l; } for (int i = 0; i < n; i++) { cin >> t; node[i].px = t; } sort(node, node + n, cmp_px); for (int i = 1; i < n; i++) { if (node[i].a > node[i - 1].a) continue; int cha = node[i - 1].a - node[i].a; node[i].a = node[i].a + cha + 1; node[i].c += cha + 1; if (node[i].c > r) { cout << -1 << endl; return 0; } } { sort(node, node + n, cmp_ori); for (int i = 0; i < n; i++) { cout << node[i].c << ; } } return 0; }
|
#include <bits/stdc++.h> using namespace std; int main() { int sb, eb; vector<int> box; cin >> sb; for (int a = 0; a < sb; a++) { cin >> eb; box.push_back(eb); } sort(box.begin(), box.end()); for (int a = 0; a < sb; a++) { cout << box[a] << ; } }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.