From 0cb0d11ba9973ea9fd683ee00c390429674f6cc0 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 3 Feb 2025 19:03:39 -0500 Subject: [PATCH] feat(codeforces): 964) --- codeforces/964/.clang-format | 9 ++ codeforces/964/a.cc | 79 ++++++++++++++++ codeforces/964/a.in | 9 ++ codeforces/964/a.out | 8 ++ codeforces/964/b.cc | 100 ++++++++++++++++++++ codeforces/964/b.in | 6 ++ codeforces/964/b.out | 5 + codeforces/964/c.cc | 118 ++++++++++++++++++++++++ codeforces/964/c.in | 17 ++++ codeforces/964/c.out | 4 + codeforces/964/compile_flags.txt | 5 + codeforces/964/d.cc | 125 +++++++++++++++++++++++++ codeforces/964/d.in | 13 +++ codeforces/964/d.out | 10 ++ codeforces/964/e.cc | 139 ++++++++++++++++++++++++++++ codeforces/964/e.in | 6 ++ codeforces/964/e.out | 7 ++ codeforces/964/f.cc | 151 +++++++++++++++++++++++++++++++ codeforces/964/f.in | 19 ++++ codeforces/964/f.out | 34 +++++++ codeforces/964/g1.cc | 114 +++++++++++++++++++++++ codeforces/964/g1.in | 8 ++ codeforces/964/g1.out | 0 codeforces/964/g2.cc | 134 +++++++++++++++++++++++++++ codeforces/964/g2.in | 0 codeforces/964/g2.out | 11 +++ 26 files changed, 1131 insertions(+) create mode 100644 codeforces/964/.clang-format create mode 100644 codeforces/964/a.cc create mode 100644 codeforces/964/a.in create mode 100644 codeforces/964/a.out create mode 100644 codeforces/964/b.cc create mode 100644 codeforces/964/b.in create mode 100644 codeforces/964/b.out create mode 100644 codeforces/964/c.cc create mode 100644 codeforces/964/c.in create mode 100644 codeforces/964/c.out create mode 100644 codeforces/964/compile_flags.txt create mode 100644 codeforces/964/d.cc create mode 100644 codeforces/964/d.in create mode 100644 codeforces/964/d.out create mode 100644 codeforces/964/e.cc create mode 100644 codeforces/964/e.in create mode 100644 codeforces/964/e.out create mode 100644 codeforces/964/f.cc create mode 100644 codeforces/964/f.in create mode 100644 codeforces/964/f.out create mode 100644 codeforces/964/g1.cc create mode 100644 codeforces/964/g1.in create mode 100644 codeforces/964/g1.out create mode 100644 codeforces/964/g2.cc create mode 100644 codeforces/964/g2.in create mode 100644 codeforces/964/g2.out diff --git a/codeforces/964/.clang-format b/codeforces/964/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/964/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: Google +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/codeforces/964/a.cc b/codeforces/964/a.cc new file mode 100644 index 0000000..7061a2b --- /dev/null +++ b/codeforces/964/a.cc @@ -0,0 +1,79 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template void dbg(T const &t) { std::cout << t; } + +template void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { std::cout << '\n'; } + +template void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template constexpr T MIN = std::numeric_limits::min(); + +template constexpr T MAX = std::numeric_limits::min(); + +template static T sc(auto &&x) { return static_cast(x); } + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +std::random_device rd; +std::mt19937 gen(rd()); + +void solve() { + int n; + cin >> n; + cout << (n % 10) + n / 10 << endl; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/964/a.in b/codeforces/964/a.in new file mode 100644 index 0000000..c06c3a6 --- /dev/null +++ b/codeforces/964/a.in @@ -0,0 +1,9 @@ +8 +77 +21 +40 +34 +19 +84 +10 +99 diff --git a/codeforces/964/a.out b/codeforces/964/a.out new file mode 100644 index 0000000..109c7ca --- /dev/null +++ b/codeforces/964/a.out @@ -0,0 +1,8 @@ +14 +3 +4 +7 +10 +12 +1 +18 diff --git a/codeforces/964/b.cc b/codeforces/964/b.cc new file mode 100644 index 0000000..d3171de --- /dev/null +++ b/codeforces/964/b.cc @@ -0,0 +1,100 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +std::random_device rd; +std::mt19937 gen(rd()); + +void solve() { + int A, B, C, D; + cin >> A >> B >> C >> D; + + auto count = [](int a, int b, int c, int d) { + return int(a > c && b >= d) + int(a == c && b > d); + }; + + cout << (count(A, B, C, D) + count(A, B, D, C) + count(B, A, C, D) + + count(B, A, D, C)) + << endl; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/964/b.in b/codeforces/964/b.in new file mode 100644 index 0000000..3d4804a --- /dev/null +++ b/codeforces/964/b.in @@ -0,0 +1,6 @@ +5 +3 8 2 6 +1 1 1 1 +10 10 2 2 +1 1 10 10 +3 8 7 2 diff --git a/codeforces/964/b.out b/codeforces/964/b.out new file mode 100644 index 0000000..bc099b6 --- /dev/null +++ b/codeforces/964/b.out @@ -0,0 +1,5 @@ +2 +0 +4 +0 +2 diff --git a/codeforces/964/c.cc b/codeforces/964/c.cc new file mode 100644 index 0000000..f0f9c32 --- /dev/null +++ b/codeforces/964/c.cc @@ -0,0 +1,118 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +static void YES() { + dbgln("YES"); +} +static void NO() { + dbgln("NO"); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +std::random_device rd; +std::mt19937 gen(rd()); + +void solve() { + int n, s, m; + cin >> n >> s >> m; + + int prev = 0; + bool can = 0; + + while (n--) { + int l, r; + cin >> l >> r; + if (l - prev >= s) + can |= 1; + prev = r; + } + + if (m - prev >= s) + can |= 1; + + if (can) + YES(); + else + NO(); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/964/c.in b/codeforces/964/c.in new file mode 100644 index 0000000..10e395c --- /dev/null +++ b/codeforces/964/c.in @@ -0,0 +1,17 @@ +4 +3 3 10 +3 5 +6 8 +9 10 +3 3 10 +1 2 +3 5 +6 7 +3 3 10 +1 2 +3 5 +6 8 +3 4 10 +1 2 +6 7 +8 9 diff --git a/codeforces/964/c.out b/codeforces/964/c.out new file mode 100644 index 0000000..16c3a96 --- /dev/null +++ b/codeforces/964/c.out @@ -0,0 +1,4 @@ +YES +YES +NO +YES diff --git a/codeforces/964/compile_flags.txt b/codeforces/964/compile_flags.txt new file mode 100644 index 0000000..b5d4b68 --- /dev/null +++ b/codeforces/964/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wpedantic +-Wshadow diff --git a/codeforces/964/d.cc b/codeforces/964/d.cc new file mode 100644 index 0000000..e2478ec --- /dev/null +++ b/codeforces/964/d.cc @@ -0,0 +1,125 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +static void YES() { + dbgln("YES"); +} +static void NO() { + dbgln("NO"); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +std::random_device rd; +std::mt19937 gen(rd()); + +void solve() { + string s, t; + cin >> s >> t; + + if (sz(s) < sz(t)) { + NO(); + return; + } + + int j = 0; + FOR(i, 0, sz(s)) { + if (j >= sz(t)) { + if (s[i] == '?') + s[i] = 'a'; + } + if (s[i] != t[j]) { + if (s[i] != '?') + continue; + s[i] = t[j++]; + } else if (s[i] == t[j]) + ++j; + } + + if (j < sz(t)) { + NO(); + } else { + YES(); + dbgln(s); + } +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/964/d.in b/codeforces/964/d.in new file mode 100644 index 0000000..7a6a748 --- /dev/null +++ b/codeforces/964/d.in @@ -0,0 +1,13 @@ +6 +a?b?c?d?? +xxx +????? +xbx +ab??e +abcde +ayy?x +a +ab??e +dac +paiu +mom diff --git a/codeforces/964/d.out b/codeforces/964/d.out new file mode 100644 index 0000000..1a85d5b --- /dev/null +++ b/codeforces/964/d.out @@ -0,0 +1,10 @@ +YES +axbxcxdaa +YES +xbxaa +YES +abcde +YES +ayyax +NO +NO diff --git a/codeforces/964/e.cc b/codeforces/964/e.cc new file mode 100644 index 0000000..e4e5155 --- /dev/null +++ b/codeforces/964/e.cc @@ -0,0 +1,139 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +std::random_device rd; +std::mt19937 gen(rd()); + +long long power(long long base, long long exp) { + long long result = 1; + while (exp > 0) { + if (exp & 1) + result *= base; + base *= base; + exp >>= 1; + } + return result; +} + +ll log_baseb(ll x, ll b) { + ll res = 0; + while (x >= b) { + x /= b; + res++; + } + return res; +} + +ll ceil_log_baseb(ll x, ll base) { + ll res = 0, power = 1; + while (power < x) { + power *= base; + res++; + } + return res; +} + +void solve() { + ll l, r; + cin >> l >> r; + + ll ans = l == 1 ? 1 : 1 + log_baseb(l, 3); + if (r - l + 1 > 1) + ans *= 2; + + // add on count to reduce range [l+1,r] to 0 + + ll L = l + 1; + + while (L <= r) { + ll B = min(r + 1, (ll)power(3, 1 + log_baseb(L, 3))); + // dbgln("floor(log({})/log(3))={}", L, log_baseb(L, 3)); + // dbgln("L={}, B={}", L, B); + ans += ceil_log_baseb(B, 3) * (B - L); + L = B; + } + + dbgln(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/964/e.in b/codeforces/964/e.in new file mode 100644 index 0000000..3d0d8b1 --- /dev/null +++ b/codeforces/964/e.in @@ -0,0 +1,6 @@ +5 +1 3 +2 4 +199999 200000 +19 84 +10 100000000 diff --git a/codeforces/964/e.out b/codeforces/964/e.out new file mode 100644 index 0000000..5c41d91 --- /dev/null +++ b/codeforces/964/e.out @@ -0,0 +1,7 @@ +5 +6 +36 +263 +1635429922 + +24:10 03/02/25 \ No newline at end of file diff --git a/codeforces/964/f.cc b/codeforces/964/f.cc new file mode 100644 index 0000000..c52cdfe --- /dev/null +++ b/codeforces/964/f.cc @@ -0,0 +1,151 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = (b); a < (c); ++a) +#define ROF(a, b, c) for (int a = (b); a > (c); --a) + +std::random_device rd; +std::mt19937 gen(rd()); + +static constexpr int MOD = 1000000007; +static constexpr int MAX_N = 2 * 100000 + 1; + +static vec fac(MAX_N + 1, 1); +bitset seen; + +void solve() { + int n, k; + cin >> n >> k; + vec a(n); + seen.reset(); + for (auto &e : a) { + cin >> e; + } + sort(all(a)); + + ll ans = 0; + dbgln("----------------------"); + dbgln(a); + + FOR(i, 0, n) { + if (a[i] == 0 || seen[a[i]]) + continue; + seen[a[i]] = true; + // count <=, >= + int lt = distance(a.begin(), lower_bound(all(a), a[i])); + int gt = distance(upper_bound(all(a), a[i]), a.end()); + int eq = n - lt - gt - 1; + + if (lt + eq < k / 2) + continue; + eq -= max(0, k / 2 - lt); + if (gt + eq < k / 2) + continue; + eq -= max(0, k / 2 - gt); + + dbgln("x={}, lt={}, gt={}, remaining eq={}", a[i], lt, gt, eq); + ans = (ans + (max(1, lt) * max(1, gt)) % MOD) % MOD; + + // count = + int left = eq; + if (lt < k / 2) + eq -= k / 2 - lt; + if (gt < k / 2) + eq -= k / 2 - gt; + + // - max(0, (k / 2 - lt)) - max(0, (k / 2 - gt)) + 1; + // dbgln("with element {}, have {} choices", a[i], left); + // FOR(i, 1, left) { + // ll nci = fac[left] / (fac[i] * fac[left - i]); + // dbgln("n={} choose i={}, nci={}", n, i, nci); + // ans = (ans + nci) % MOD; + // } + // } + + dbgln(ans); + } +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + fac[0] = 1LL; + FOR(i, 1, MAX_N + 1) { + fac[i] = i * fac[i - 1]; + } + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/964/f.in b/codeforces/964/f.in new file mode 100644 index 0000000..db5311b --- /dev/null +++ b/codeforces/964/f.in @@ -0,0 +1,19 @@ +9 +4 3 +1 0 0 1 +5 1 +1 1 1 1 1 +5 5 +0 1 0 1 0 +6 3 +1 0 1 0 1 1 +4 3 +1 0 1 1 +5 3 +1 0 1 1 0 +2 1 +0 0 +34 17 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +4 3 +0 1 2 2 diff --git a/codeforces/964/f.out b/codeforces/964/f.out new file mode 100644 index 0000000..eb65460 --- /dev/null +++ b/codeforces/964/f.out @@ -0,0 +1,34 @@ +---------------------- +0 0 1 1 +x=1, lt=2, gt=0, remaining eq=0 +2 +---------------------- +1 1 1 1 1 +x=1, lt=0, gt=0, remaining eq=4 +1 +---------------------- +0 0 0 1 1 +---------------------- +0 0 1 1 1 1 +x=1, lt=2, gt=0, remaining eq=2 +2 +---------------------- +0 1 1 1 +x=1, lt=1, gt=0, remaining eq=1 +1 +---------------------- +0 0 1 1 1 +x=1, lt=2, gt=0, remaining eq=1 +2 +---------------------- +0 0 +---------------------- +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +x=1, lt=0, gt=0, remaining eq=17 +1 +---------------------- +0 1 2 2 +x=1, lt=1, gt=2, remaining eq=0 +2 +x=2, lt=2, gt=0, remaining eq=0 +4 diff --git a/codeforces/964/g1.cc b/codeforces/964/g1.cc new file mode 100644 index 0000000..2ca8789 --- /dev/null +++ b/codeforces/964/g1.cc @@ -0,0 +1,114 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +std::random_device rd; +std::mt19937 gen(rd()); + +void solve() { + int l = 2, r = 1000; + + while (l <= r) { + int m = l + (r - l) / 2; + + dbgln("? {} {}", m, m); + cout.flush(); + int area; + cin >> area; + if (area == m * m) { + l = m + 1; + } else { + r = m - 1; + } + } + + dbgln("! {}", l); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) + solve(); + + return 0; +} diff --git a/codeforces/964/g1.in b/codeforces/964/g1.in new file mode 100644 index 0000000..21dcda7 --- /dev/null +++ b/codeforces/964/g1.in @@ -0,0 +1,8 @@ +2 + +18 + +25 + + +9999 diff --git a/codeforces/964/g1.out b/codeforces/964/g1.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/964/g2.cc b/codeforces/964/g2.cc new file mode 100644 index 0000000..36187e6 --- /dev/null +++ b/codeforces/964/g2.cc @@ -0,0 +1,134 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +std::random_device rd; +std::mt19937 gen(rd()); + +void solve() { + int l = 2, r = 999; + + while (l < r) { + int x, y; + + if (r - l == 1) { + dbgln("? {} {}", l, l); + cout.flush(); + int area; + cin >> area; + if (area != (l + 1) * (l + 1)) { + l = r; + } + break; + } else if (r - l == 2) { + x = l + 1, y = r - 1; + } else { + x = l + (r - l) / 3; + y = r - (r - l) / 3; + } + + dbgln("? {} {}", x, y); + cout.flush(); + int area; + cin >> area; + + if (area == x * y) { + l = y + 1; + } else if (area == x * (y + 1)) { + l = x + 1; + r = y; + } else { + r = x; + } + } + + dbgln("! {}", l); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) + solve(); + + return 0; +} diff --git a/codeforces/964/g2.in b/codeforces/964/g2.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/964/g2.out b/codeforces/964/g2.out new file mode 100644 index 0000000..8559aaa --- /dev/null +++ b/codeforces/964/g2.out @@ -0,0 +1,11 @@ +g2.cc: In function ‘int main()’: +g2.cc:132:11: error: ‘i’ was not declared in this scope + 132 | solve(i); + | ^ +g2.cc: At global scope: +g2.cc:63:13: warning: ‘void YES()’ defined but not used [-Wunused-function] + 63 | static void YES() { + | ^~~ +g2.cc:59:13: warning: ‘void NO()’ defined but not used [-Wunused-function] + 59 | static void NO() { + | ^~