From 1e18e29af4f6590177b4cc41e803779793d8bf95 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 18 May 2025 13:18:30 -0500 Subject: [PATCH] feat(codeforces/993): ak --- codeforces/817/.clangd | 1 + codeforces/817/g.cc | 45 +++--- codeforces/817/io/g.in | 1 - codeforces/817/io/g.out | 16 +- codeforces/993/.clangd | 2 + codeforces/993/debug_flags.txt | 2 +- codeforces/993/f.cc | 284 ++++++++++++--------------------- codeforces/993/f.in | 9 -- codeforces/993/{h.cpp => h.cc} | 0 codeforces/993/h.in | 16 -- codeforces/993/h.out | 2 - codeforces/993/{ => io}/a.in | 0 codeforces/993/{ => io}/b.in | 0 codeforces/993/{ => io}/b.out | 0 codeforces/993/{ => io}/c.in | 0 codeforces/993/{ => io}/c.out | 0 codeforces/993/{ => io}/d.in | 0 codeforces/993/{ => io}/d.out | 0 codeforces/993/{ => io}/e.in | 0 codeforces/993/{ => io}/e.out | 0 codeforces/993/io/f.in | 10 ++ codeforces/993/io/f.out | 9 ++ codeforces/993/{ => io}/g1.in | 0 codeforces/993/{ => io}/g1.out | 0 codeforces/993/io/h.out | 7 +- codeforces/993/makefile | 1 + 26 files changed, 158 insertions(+), 247 deletions(-) delete mode 100644 codeforces/993/f.in rename codeforces/993/{h.cpp => h.cc} (100%) delete mode 100644 codeforces/993/h.in delete mode 100644 codeforces/993/h.out rename codeforces/993/{ => io}/a.in (100%) rename codeforces/993/{ => io}/b.in (100%) rename codeforces/993/{ => io}/b.out (100%) rename codeforces/993/{ => io}/c.in (100%) rename codeforces/993/{ => io}/c.out (100%) rename codeforces/993/{ => io}/d.in (100%) rename codeforces/993/{ => io}/d.out (100%) rename codeforces/993/{ => io}/e.in (100%) rename codeforces/993/{ => io}/e.out (100%) create mode 100644 codeforces/993/io/f.in create mode 100644 codeforces/993/io/f.out rename codeforces/993/{ => io}/g1.in (100%) rename codeforces/993/{ => io}/g1.out (100%) diff --git a/codeforces/817/.clangd b/codeforces/817/.clangd index 20950b9..816936a 100644 --- a/codeforces/817/.clangd +++ b/codeforces/817/.clangd @@ -39,3 +39,4 @@ CompileFlags: -std=c++23 -std=c++23 -std=c++23 + -std=c++23 diff --git a/codeforces/817/g.cc b/codeforces/817/g.cc index 8df51df..dc2efef 100644 --- a/codeforces/817/g.cc +++ b/codeforces/817/g.cc @@ -61,37 +61,36 @@ void solve() { u32 n; cin >> n; - vec a(n); - for (u32 i = 0; i < n; i += 2) a[i] = i >> 1; - - u32 xe = 0; - for (u32 i = 0; i < n; i += 2) xe ^= a[i]; - - u32 odd = n >> 1; - if (!odd) { - for (u32 i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1]; + if (n == 3) { + cout << "1 2 3\n"; return; } - const u32 BIG = 1u << 20; - u32 xo = 0; - for (u32 k = 0; k + 2 < odd; ++k) { - a[1 + 2 * k] = BIG + k; - xo ^= a[1 + 2 * k]; + vec a(n, 0); + + u32 odd_slots = n / 2; + u32 even_slots = ceil(n / 2.0); + + for (u32 i = 0; i < n; i += 2) { + a[i] = i / 2 + 1; + if (i + 1 < n) + a[i + 1] = a[i] | ((u32)1 << 30); } - if (odd == 1) { - a[1] = BIG; - a[0] ^= xe ^ BIG; - } else { - u32 diff = xe ^ xo; - u32 p = BIG + odd - 2; - a[2 * odd - 3] = p; - a[2 * odd - 1] = p ^ diff; + if (n & 1) { + a[n - 1] = 0; } - for (u32 i = 0; i < n; ++i) + if (odd_slots & 1) { + a[odd_slots * 2 - 3] ^= a[odd_slots * 2 - 1]; + a[odd_slots * 2 - 1] = (u32)1 << 29; + a[odd_slots * 2 - 3] |= (u32)1 << 29; + a[odd_slots * 2 - 3] |= (u32)1 << 30; + } + + for (u32 i = 0; i < n; ++i) { cout << a[i] << " \n"[i == n - 1]; + } } int main() { // {{{ diff --git a/codeforces/817/io/g.in b/codeforces/817/io/g.in index 50d3eda..e4ac3ca 100644 --- a/codeforces/817/io/g.in +++ b/codeforces/817/io/g.in @@ -6,4 +6,3 @@ 6 7 9 - diff --git a/codeforces/817/io/g.out b/codeforces/817/io/g.out index fe2c84e..a555993 100644 --- a/codeforces/817/io/g.out +++ b/codeforces/817/io/g.out @@ -1,10 +1,10 @@ -0 1048576 1 1048577 2 1048578 3 1048579 -1048577 1048576 1 -0 1048576 1 1048577 -0 1048576 1 1048579 2 -0 1048576 1 1048580 2 7 -0 1048576 1 1048580 2 4 3 -0 1048576 1 1048577 2 1048578 3 1048583 4 +1 1073741825 2 1073741826 3 1073741827 4 1073741828 +1 2 3 +1 1073741825 2 1073741826 +1 1073741825 2 1073741826 0 +1 1073741825 2 1610612737 3 536870912 +1 1073741825 2 1610612737 3 536870912 0 +1 1073741825 2 1073741826 3 1073741827 4 1073741828 0 [code]: 0 -[time]: 4.62723 ms \ No newline at end of file +[time]: 4.25386 ms \ No newline at end of file diff --git a/codeforces/993/.clangd b/codeforces/993/.clangd index d02250b..2e31f27 100644 --- a/codeforces/993/.clangd +++ b/codeforces/993/.clangd @@ -34,3 +34,5 @@ CompileFlags: -std=c++23 -std=c++23 -std=c++23 + -std=c++23 + -std=c++23 diff --git a/codeforces/993/debug_flags.txt b/codeforces/993/debug_flags.txt index af1b521..62a0135 100644 --- a/codeforces/993/debug_flags.txt +++ b/codeforces/993/debug_flags.txt @@ -11,4 +11,4 @@ -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -DLOCAL --std=c++20 +-std=c++23 diff --git a/codeforces/993/f.cc b/codeforces/993/f.cc index 3ae6e75..1c0bbc3 100644 --- a/codeforces/993/f.cc +++ b/codeforces/993/f.cc @@ -1,4 +1,4 @@ -#include +#include // {{{ // https://codeforces.com/blog/entry/96344 @@ -7,214 +7,134 @@ using namespace std; -template -void dbg(std::string const &str, Args &&...args) { - std::cout << std::vformat(str, - // make_format_args binds arguments to const - std::make_format_args(args...)); +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); } template -void dbg(T const &t) { - std::cout << t; +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; } -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'; - } -} - -template -void dbgln(std::string const &str, Args &&...args) { - dbg(str, std::forward(args)...); - cout << '\n'; +static void YES() { + std::cout << "YES\n"; } template -void dbgln(T const &t) { - dbg("{}\n", t); -} - -void println() { - std::cout << '\n'; -} - -template -constexpr auto MIN = std::numeric_limits::min(); - -template -constexpr auto MAX = std::numeric_limits::min(); - -#define ff first -#define ss second -#define eb emplace_back -#define ll long long -#define ld long double -#define vec vector +using vec = std::vector; #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 rall(x) (x).rbegin(), (x).rend() +#define ff first +#define ss second -std::random_device rd; -std::mt19937 gen(rd()); - -void YES() { - cout << "YES\n"; -} - -void NO() { - cout << "NO\n"; -} - -#include -#include - -using namespace __gnu_pbds; - -// https://mirror.codeforces.com/blog/entry/124683 - -namespace hashing { -using i64 = std::int64_t; -using u64 = std::uint64_t; -static const u64 FIXED_RANDOM = - std::chrono::steady_clock::now().time_since_epoch().count(); - -#if USE_AES -std::mt19937 rd(FIXED_RANDOM); -const __m128i KEY1{(i64)rd(), (i64)rd()}; -const __m128i KEY2{(i64)rd(), (i64)rd()}; -#endif - -template -struct custom_hash {}; - -template -inline void hash_combine(u64 &seed, T const &v) { - custom_hash hasher; - seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); -}; - -template -struct custom_hash::value>::type> { - u64 operator()(T _x) const { - u64 x = _x; -#if USE_AES - __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; - __m128i y = _mm_aesenc_si128(m, KEY1); - __m128i z = _mm_aesenc_si128(y, KEY2); - return z[0]; +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) #else - x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; - x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; - x = (x ^ (x >> 27)) * 0x94d049bb133111eb; - return x ^ (x >> 31); -#endif - } -}; - -template -struct custom_hash()))>> { - u64 operator()(T const &a) const { - u64 value = FIXED_RANDOM; - for (auto &x : a) - hash_combine(value, x); - return value; - } -}; - -template -struct custom_hash> { - u64 operator()(const std::tuple &a) const { - u64 value = FIXED_RANDOM; - std::apply( - [&value](T const &...args) { - (hash_combine(value, args), ...); - }, - a); - return value; - } -}; - -template -struct custom_hash> { - u64 operator()(std::pair const &a) const { - u64 value = FIXED_RANDOM; - hash_combine(value, a.first); - hash_combine(value, a.second); - return value; - } -}; -}; // namespace hashing - -#ifdef PB_DS_ASSOC_CNTNR_HPP -template -using hashmap = gp_hash_table< - Key, Value, hashing::custom_hash, std::equal_to, - direct_mask_range_hashing<>, linear_probe_fn<>, - hash_standard_resize_policy, - hash_load_check_resize_trigger<>, true>>; -template -using hashset = gp_hash_table< - Key, null_type, hashing::custom_hash, std::equal_to, - direct_mask_range_hashing<>, linear_probe_fn<>, - hash_standard_resize_policy, - hash_load_check_resize_trigger<>, true>>; - -#endif -#ifdef PB_DS_TREE_POLICY_HPP -template -using multiset = tree, rb_tree_tag, - tree_order_statistics_node_update>; -template -using rbtree = tree, rb_tree_tag, - tree_order_statistics_node_update>; +#define db(...) +#define dbln(...) #endif +// }}} void solve() { - int n, m, q; + const int LIM = 2 * 1e5; + bitset Apos, Aneg, Bpos, Bneg; + Apos.reset(); + Aneg.reset(); + Bpos.reset(); + Bneg.reset(); + + /* ---------- read input & build bitsets ---------- */ + u32 n, m, q; cin >> n >> m >> q; - dbgln("{} {} {}", n, m, q); - vec a(n), b(m); - for (auto &e : a) - cin >> e; - for (auto &e : b) - cin >> e; - ll bprod = accumulate(all(b), 1, multiplies()); - ll total = n * bprod + accumulate(all(a), 0LL); - - hashset hm; - - FOR(i, 0, n) { - FOR(j, 0, m) { - hm.insert(total - n * b[j] - m * a[i] + a[i] * b[j]); - } + vector a(n), b(m); + i64 A = 0, B = 0; + for (u32 i = 0; i < n; ++i) { + cin >> a[i]; + A += a[i]; + } + for (u32 i = 0; i < m; ++i) { + cin >> b[i]; + B += b[i]; } - while (q--) { + auto add_term = [](i64 t, bitset& pos, bitset& neg) { + if (t == 0 || abs(t) > LIM) + return; + (t > 0 ? pos : neg).set(abs(t)); + }; + + for (u32 i = 0; i < n; ++i) + add_term(A - a[i], Apos, Aneg); + for (u32 i = 0; i < m; ++i) + add_term(B - b[i], Bpos, Bneg); + + vec> div(LIM + 1); + for (int d = 1; d <= LIM; ++d) + for (int v = d; v <= LIM; v += d) + div[v].push_back(d); + + for (u32 _ = 0; _ < q; ++_) { int x; cin >> x; - if (hm.find(x) != hm.end()) - YES(); - else - NO(); + int y = abs(x); + bool good = false; + + for (int d : div[y]) { + int e = y / d; + + if (x > 0) { + if ((Apos[d] && Bpos[e]) || (Apos[e] && Bpos[d]) || + (Aneg[d] && Bneg[e]) || (Aneg[e] && Bneg[d])) { + good = true; + break; + } + } else { + if ((Apos[d] && Bneg[e]) || (Apos[e] && Bneg[d]) || + (Aneg[d] && Bpos[e]) || (Aneg[e] && Bpos[d])) { + good = true; + break; + } + } + } + + good ? YES() : NO(); } } -int main() { +int main() { // {{{ cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + u32 tc = 1; + // cin >> tc; + + for (u32 t = 0; t < tc; ++t) { solve(); + } return 0; } +// }}} diff --git a/codeforces/993/f.in b/codeforces/993/f.in deleted file mode 100644 index 7f40ee1..0000000 --- a/codeforces/993/f.in +++ /dev/null @@ -1,9 +0,0 @@ -3 3 6 --2 3 -3 --2 2 -1 --1 -1 --2 -2 --3 -3 diff --git a/codeforces/993/h.cpp b/codeforces/993/h.cc similarity index 100% rename from codeforces/993/h.cpp rename to codeforces/993/h.cc diff --git a/codeforces/993/h.in b/codeforces/993/h.in deleted file mode 100644 index f4f17a1..0000000 --- a/codeforces/993/h.in +++ /dev/null @@ -1,16 +0,0 @@ -2 -4 3 -1 5 2 4 -4 9 5 3 -4 5 2 3 -1 5 5 2 -1 1 4 4 -2 2 3 3 -1 2 4 3 -3 3 -1 2 3 -4 5 6 -7 8 9 -1 1 1 3 -1 3 3 3 -2 2 2 2 diff --git a/codeforces/993/h.out b/codeforces/993/h.out deleted file mode 100644 index 7452ee8..0000000 --- a/codeforces/993/h.out +++ /dev/null @@ -1,2 +0,0 @@ -hi -hi diff --git a/codeforces/993/a.in b/codeforces/993/io/a.in similarity index 100% rename from codeforces/993/a.in rename to codeforces/993/io/a.in diff --git a/codeforces/993/b.in b/codeforces/993/io/b.in similarity index 100% rename from codeforces/993/b.in rename to codeforces/993/io/b.in diff --git a/codeforces/993/b.out b/codeforces/993/io/b.out similarity index 100% rename from codeforces/993/b.out rename to codeforces/993/io/b.out diff --git a/codeforces/993/c.in b/codeforces/993/io/c.in similarity index 100% rename from codeforces/993/c.in rename to codeforces/993/io/c.in diff --git a/codeforces/993/c.out b/codeforces/993/io/c.out similarity index 100% rename from codeforces/993/c.out rename to codeforces/993/io/c.out diff --git a/codeforces/993/d.in b/codeforces/993/io/d.in similarity index 100% rename from codeforces/993/d.in rename to codeforces/993/io/d.in diff --git a/codeforces/993/d.out b/codeforces/993/io/d.out similarity index 100% rename from codeforces/993/d.out rename to codeforces/993/io/d.out diff --git a/codeforces/993/e.in b/codeforces/993/io/e.in similarity index 100% rename from codeforces/993/e.in rename to codeforces/993/io/e.in diff --git a/codeforces/993/e.out b/codeforces/993/io/e.out similarity index 100% rename from codeforces/993/e.out rename to codeforces/993/io/e.out diff --git a/codeforces/993/io/f.in b/codeforces/993/io/f.in new file mode 100644 index 0000000..e877b78 --- /dev/null +++ b/codeforces/993/io/f.in @@ -0,0 +1,10 @@ +5 5 6 +1 -2 3 0 0 +0 -2 5 0 -3 +4 +-3 +5 +2 +-1 +2 + diff --git a/codeforces/993/io/f.out b/codeforces/993/io/f.out new file mode 100644 index 0000000..d2a4a82 --- /dev/null +++ b/codeforces/993/io/f.out @@ -0,0 +1,9 @@ +YES +YES +YES +YES +NO +YES + +[code]: 0 +[time]: 110.999 ms \ No newline at end of file diff --git a/codeforces/993/g1.in b/codeforces/993/io/g1.in similarity index 100% rename from codeforces/993/g1.in rename to codeforces/993/io/g1.in diff --git a/codeforces/993/g1.out b/codeforces/993/io/g1.out similarity index 100% rename from codeforces/993/g1.out rename to codeforces/993/io/g1.out diff --git a/codeforces/993/io/h.out b/codeforces/993/io/h.out index 928561e..7452ee8 100644 --- a/codeforces/993/io/h.out +++ b/codeforces/993/io/h.out @@ -1,5 +1,2 @@ -500 42 168 -14 42 5 - -[code]: 0 -[time]: 4.26412 ms +hi +hi diff --git a/codeforces/993/makefile b/codeforces/993/makefile index 78778b6..3c50267 100644 --- a/codeforces/993/makefile +++ b/codeforces/993/makefile @@ -19,6 +19,7 @@ setup: test -d build || mkdir -p build test -d io || mkdir -p io test -d scripts || mkdir -p scripts + test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format . test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd