/* * @Author: Tifa * @Description: From <https://github.com/Tiphereth-A/CP-archives> * !!! ATTENEION: All the context below is licensed under a * GNU Affero General Public License, Version 3. * See <https://www.gnu.org/licenses/agpl-3.0.txt>. */ #include<bits/stdc++.h> usingnamespace std; constint N = 1 << 21; int cnt[N] = {1}; intmain(){ int n; cin >> n; int state = 0; int64_t ans = 0; for (int i = 1, _; i <= n; ++i) { cin >> _; ans += cnt[state ^= (1 << _)]++; } cout << ans; return0; }
/* * @Author: Tifa * @Description: From <https://github.com/Tiphereth-A/CP-archives> * !!! ATTENEION: All the context below is licensed under a * GNU Affero General Public License, Version 3. * See <https://www.gnu.org/licenses/agpl-3.0.txt>. */ #include<bits/stdc++.h> usingnamespace std; using i128 = __int128_t; constint num_stick[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int n; i128 max_ans; booldfs(i128 ans = 0, int sum = 0, int dep = 0){ if (sum > n) returnfalse; if (sum == n) { max_ans = max(max_ans, ans); returntrue; } bool f = false; for (int i = 0; i < 10; ++i) if ((ans * 10 + i) % (dep + 1) == 0) f |= dfs(ans * 10 + i, sum + num_stick[i], dep + 1); return f; } ostream &operator<<(ostream &os, i128 n) { if (n < 0) { os << '-'; n = -n; } if (n > 9) os << (i128)(n / 10); os << (int)(n % 10); return os; } intmain(){ cin >> n; if (n > 139 || !dfs()) { cout << -1; return0; } cout << max_ans; return0; }
/* * @Author: Tifa * @Description: From <https://github.com/Tiphereth-A/CP-archives> * !!! ATTENEION: All the context below is licensed under a * GNU Affero General Public License, Version 3. * See <https://www.gnu.org/licenses/agpl-3.0.txt>. */ #include<bits/stdc++.h> usingnamespace std; constint M = 22505, N = 155; int sg[N][N]; intf(int m, int n){ if (~sg[m][n]) return sg[m][n]; bool vis[M]; memset(vis, 0, sizeof(vis)); for (int i = 1; i <= m - i; ++i) { if ((i == 1 && n == 1) || (m - i == 1 && n == 1)) continue; vis[f(i, n) ^ f(m - i, n)] = 1; } for (int i = 1; i <= n - i; ++i) { if ((i == 1 && m == 1) || (n - i == 1 && m == 1)) continue; vis[f(m, i) ^ f(m, n - i)] = 1; } for (int i = 0; i < M; ++i) if (!vis[i]) return sg[m][n] = i; } intmain(){ int m, n; memset(sg, 0xff, sizeof(sg)); sg[1][1] = sg[1][2] = sg[2][1] = sg[1][3] = sg[3][1] = 0; while (cin >> m >> n) cout << (f(m, n) ? "Alice" : "Bob") << endl; return0; }
/* * @Author: Tifa * @Description: From <https://github.com/Tiphereth-A/CP-archives> * !!! ATTENEION: All the context below is licensed under a * GNU Affero General Public License, Version 3. * See <https://www.gnu.org/licenses/agpl-3.0.txt>. */ #include<bits/stdc++.h> usingnamespace std; template <const std::size_t N = (std::size_t)1e2 + 5, classgraph_t = std::ptrdiff_t> class Floyd { private: std::size_t n; graph_t spath[N][N];
public: Floyd(std::size_t _n = N - 1): n(_n) { memset(spath, 0x3f, sizeof(spath)); for (std::size_t i = 1; i <= n; ++i) spath[i][i] = 0; } voidresize(std::size_t _n){ n = _n; } voidclear(){ memset(spath, 0, sizeof(spath)); } voidaddedge(std::size_t from, std::size_t to, graph_t w = 1){ spath[from][to] = w; } voidget_all_spath(){ for (std::size_t k = 1; k <= n; ++k) for (std::size_t i = 1; i <= n; ++i) for (std::size_t j = 1; j <= n; ++j) if (spath[i][k] + spath[k][j] < spath[i][j]) spath[i][j] = spath[i][k] + spath[k][j]; } constgraph_t &operator()(std::size_t from, std::size_t to){ return spath[from][to]; } }; Floyd<> f; booljudge(int64_t k, int64_t l, int64_t b){ if (k > 1) return l * log(k) <= log(b + 1 - 1.0 * b / k); elseif (k == 1) return l <= b; elsereturn b >= 0; } intmain(){ int m, n; cin >> n >> m; f.resize(n); for (int i = 1, u, v; i <= m; ++i) { cin >> u >> v; f.addedge(u, v); f.addedge(v, u); } f.get_all_spath(); int q; cin >> q; for (int i = 1, s, t, b; i <= q; ++i) { cin >> s >> t >> b; int64_t l = f(s, t); int64_t left = 0, right = b, mid, k; while (left <= right) { mid = left + ((right - left) >> 1); if (judge(mid, l, b)) { k = mid; left = mid + 1; } else right = mid - 1; } cout << k << endl; } return0; }