feat(codeforces/993): ak
This commit is contained in:
parent
ee35513364
commit
1e18e29af4
26 changed files with 158 additions and 247 deletions
|
|
@ -39,3 +39,4 @@ CompileFlags:
|
||||||
-std=c++23
|
-std=c++23
|
||||||
-std=c++23
|
-std=c++23
|
||||||
-std=c++23
|
-std=c++23
|
||||||
|
-std=c++23
|
||||||
|
|
|
||||||
|
|
@ -61,37 +61,36 @@ void solve() {
|
||||||
u32 n;
|
u32 n;
|
||||||
cin >> n;
|
cin >> n;
|
||||||
|
|
||||||
vec<u32> a(n);
|
if (n == 3) {
|
||||||
for (u32 i = 0; i < n; i += 2) a[i] = i >> 1;
|
cout << "1 2 3\n";
|
||||||
|
|
||||||
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];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32 BIG = 1u << 20;
|
vec<u32> a(n, 0);
|
||||||
u32 xo = 0;
|
|
||||||
for (u32 k = 0; k + 2 < odd; ++k) {
|
u32 odd_slots = n / 2;
|
||||||
a[1 + 2 * k] = BIG + k;
|
u32 even_slots = ceil(n / 2.0);
|
||||||
xo ^= a[1 + 2 * k];
|
|
||||||
|
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) {
|
if (n & 1) {
|
||||||
a[1] = BIG;
|
a[n - 1] = 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
cout << a[i] << " \n"[i == n - 1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() { // {{{
|
int main() { // {{{
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,3 @@
|
||||||
6
|
6
|
||||||
7
|
7
|
||||||
9
|
9
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
0 1048576 1 1048577 2 1048578 3 1048579
|
1 1073741825 2 1073741826 3 1073741827 4 1073741828
|
||||||
1048577 1048576 1
|
1 2 3
|
||||||
0 1048576 1 1048577
|
1 1073741825 2 1073741826
|
||||||
0 1048576 1 1048579 2
|
1 1073741825 2 1073741826 0
|
||||||
0 1048576 1 1048580 2 7
|
1 1073741825 2 1610612737 3 536870912
|
||||||
0 1048576 1 1048580 2 4 3
|
1 1073741825 2 1610612737 3 536870912 0
|
||||||
0 1048576 1 1048577 2 1048578 3 1048583 4
|
1 1073741825 2 1073741826 3 1073741827 4 1073741828 0
|
||||||
|
|
||||||
[code]: 0
|
[code]: 0
|
||||||
[time]: 4.62723 ms
|
[time]: 4.25386 ms
|
||||||
|
|
@ -34,3 +34,5 @@ CompileFlags:
|
||||||
-std=c++23
|
-std=c++23
|
||||||
-std=c++23
|
-std=c++23
|
||||||
-std=c++23
|
-std=c++23
|
||||||
|
-std=c++23
|
||||||
|
-std=c++23
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,4 @@
|
||||||
-D_GLIBCXX_DEBUG
|
-D_GLIBCXX_DEBUG
|
||||||
-D_GLIBCXX_DEBUG_PEDANTIC
|
-D_GLIBCXX_DEBUG_PEDANTIC
|
||||||
-DLOCAL
|
-DLOCAL
|
||||||
-std=c++20
|
-std=c++23
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include <bits/stdc++.h>
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
// https://codeforces.com/blog/entry/96344
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
|
@ -7,214 +7,134 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
template <typename... Args>
|
using i32 = int32_t;
|
||||||
void dbg(std::string const &str, Args &&...args) {
|
using u32 = uint32_t;
|
||||||
std::cout << std::vformat(str,
|
using i64 = int64_t;
|
||||||
// make_format_args binds arguments to const
|
using u64 = uint64_t;
|
||||||
std::make_format_args(args...));
|
using f64 = double;
|
||||||
|
using f128 = long double;
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002L
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void dbg(T const &t) {
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
std::cout << t;
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::ranges::range T>
|
static void YES() {
|
||||||
void dbgln(T const &t) {
|
std::cout << "YES\n";
|
||||||
if constexpr (std::is_convertible_v<T, char const *>) {
|
|
||||||
std::cout << t << '\n';
|
|
||||||
} else {
|
|
||||||
for (auto const &e : t) {
|
|
||||||
std::cout << e << ' ';
|
|
||||||
}
|
|
||||||
std::cout << '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
void dbgln(std::string const &str, Args &&...args) {
|
|
||||||
dbg(str, std::forward<Args>(args)...);
|
|
||||||
cout << '\n';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void dbgln(T const &t) {
|
using vec = std::vector<T>;
|
||||||
dbg("{}\n", t);
|
|
||||||
}
|
|
||||||
|
|
||||||
void println() {
|
|
||||||
std::cout << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
constexpr auto MIN = std::numeric_limits<T>::min();
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
constexpr auto MAX = std::numeric_limits<T>::min();
|
|
||||||
|
|
||||||
#define ff first
|
|
||||||
#define ss second
|
|
||||||
#define eb emplace_back
|
|
||||||
#define ll long long
|
|
||||||
#define ld long double
|
|
||||||
#define vec vector
|
|
||||||
|
|
||||||
#define all(x) (x).begin(), (x).end()
|
#define all(x) (x).begin(), (x).end()
|
||||||
#define rall(x) (r).rbegin(), (x).rend()
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
#define sz(x) static_cast<int>((x).size())
|
#define ff first
|
||||||
#define FOR(a, b, c) for (int a = b; a < c; ++a)
|
#define ss second
|
||||||
|
|
||||||
std::random_device rd;
|
#ifdef LOCAL
|
||||||
std::mt19937 gen(rd());
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
void YES() {
|
|
||||||
cout << "YES\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void NO() {
|
|
||||||
cout << "NO\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <ext/pb_ds/assoc_container.hpp>
|
|
||||||
#include <ext/pb_ds/tree_policy.hpp>
|
|
||||||
|
|
||||||
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 <class T, class D = void>
|
|
||||||
struct custom_hash {};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline void hash_combine(u64 &seed, T const &v) {
|
|
||||||
custom_hash<T> hasher;
|
|
||||||
seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4);
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
struct custom_hash<T,
|
|
||||||
typename std::enable_if<std::is_integral<T>::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];
|
|
||||||
#else
|
#else
|
||||||
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
|
#define db(...)
|
||||||
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
|
#define dbln(...)
|
||||||
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
|
|
||||||
return x ^ (x >> 31);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
struct custom_hash<T, std::void_t<decltype(std::begin(std::declval<T>()))>> {
|
|
||||||
u64 operator()(T const &a) const {
|
|
||||||
u64 value = FIXED_RANDOM;
|
|
||||||
for (auto &x : a)
|
|
||||||
hash_combine(value, x);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class... T>
|
|
||||||
struct custom_hash<std::tuple<T...>> {
|
|
||||||
u64 operator()(const std::tuple<T...> &a) const {
|
|
||||||
u64 value = FIXED_RANDOM;
|
|
||||||
std::apply(
|
|
||||||
[&value](T const &...args) {
|
|
||||||
(hash_combine(value, args), ...);
|
|
||||||
},
|
|
||||||
a);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T, class U>
|
|
||||||
struct custom_hash<std::pair<T, U>> {
|
|
||||||
u64 operator()(std::pair<T, U> 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 <class Key, class Value>
|
|
||||||
using hashmap = gp_hash_table<
|
|
||||||
Key, Value, hashing::custom_hash<Key>, std::equal_to<Key>,
|
|
||||||
direct_mask_range_hashing<>, linear_probe_fn<>,
|
|
||||||
hash_standard_resize_policy<hash_exponential_size_policy<>,
|
|
||||||
hash_load_check_resize_trigger<>, true>>;
|
|
||||||
template <class Key>
|
|
||||||
using hashset = gp_hash_table<
|
|
||||||
Key, null_type, hashing::custom_hash<Key>, std::equal_to<Key>,
|
|
||||||
direct_mask_range_hashing<>, linear_probe_fn<>,
|
|
||||||
hash_standard_resize_policy<hash_exponential_size_policy<>,
|
|
||||||
hash_load_check_resize_trigger<>, true>>;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#ifdef PB_DS_TREE_POLICY_HPP
|
|
||||||
template <typename T>
|
|
||||||
using multiset = tree<T, null_type, std::less_equal<T>, rb_tree_tag,
|
|
||||||
tree_order_statistics_node_update>;
|
|
||||||
template <class Key, class Value = null_type>
|
|
||||||
using rbtree = tree<Key, Value, std::less<Key>, rb_tree_tag,
|
|
||||||
tree_order_statistics_node_update>;
|
|
||||||
#endif
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
void solve() {
|
void solve() {
|
||||||
int n, m, q;
|
const int LIM = 2 * 1e5;
|
||||||
|
bitset<LIM + 1> Apos, Aneg, Bpos, Bneg;
|
||||||
|
Apos.reset();
|
||||||
|
Aneg.reset();
|
||||||
|
Bpos.reset();
|
||||||
|
Bneg.reset();
|
||||||
|
|
||||||
|
/* ---------- read input & build bitsets ---------- */
|
||||||
|
u32 n, m, q;
|
||||||
cin >> n >> m >> q;
|
cin >> n >> m >> q;
|
||||||
dbgln("{} {} {}", n, m, q);
|
|
||||||
vec<ll> a(n), b(m);
|
|
||||||
for (auto &e : a)
|
|
||||||
cin >> e;
|
|
||||||
for (auto &e : b)
|
|
||||||
cin >> e;
|
|
||||||
|
|
||||||
ll bprod = accumulate(all(b), 1, multiplies<int>());
|
vector<i64> a(n), b(m);
|
||||||
ll total = n * bprod + accumulate(all(a), 0LL);
|
i64 A = 0, B = 0;
|
||||||
|
for (u32 i = 0; i < n; ++i) {
|
||||||
hashset<ll> hm;
|
cin >> a[i];
|
||||||
|
A += a[i];
|
||||||
FOR(i, 0, n) {
|
}
|
||||||
FOR(j, 0, m) {
|
for (u32 i = 0; i < m; ++i) {
|
||||||
hm.insert(total - n * b[j] - m * a[i] + a[i] * b[j]);
|
cin >> b[i];
|
||||||
}
|
B += b[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
while (q--) {
|
auto add_term = [](i64 t, bitset<LIM + 1>& pos, bitset<LIM + 1>& 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<vec<u32>> 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;
|
int x;
|
||||||
cin >> x;
|
cin >> x;
|
||||||
if (hm.find(x) != hm.end())
|
int y = abs(x);
|
||||||
YES();
|
bool good = false;
|
||||||
else
|
|
||||||
NO();
|
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.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
u32 tc = 1;
|
||||||
|
// cin >> tc;
|
||||||
|
|
||||||
|
for (u32 t = 0; t < tc; ++t) {
|
||||||
solve();
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
3 3 6
|
|
||||||
-2 3 -3
|
|
||||||
-2 2 -1
|
|
||||||
-1
|
|
||||||
1
|
|
||||||
-2
|
|
||||||
2
|
|
||||||
-3
|
|
||||||
3
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
hi
|
|
||||||
hi
|
|
||||||
10
codeforces/993/io/f.in
Normal file
10
codeforces/993/io/f.in
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
5 5 6
|
||||||
|
1 -2 3 0 0
|
||||||
|
0 -2 5 0 -3
|
||||||
|
4
|
||||||
|
-3
|
||||||
|
5
|
||||||
|
2
|
||||||
|
-1
|
||||||
|
2
|
||||||
|
|
||||||
9
codeforces/993/io/f.out
Normal file
9
codeforces/993/io/f.out
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
YES
|
||||||
|
YES
|
||||||
|
YES
|
||||||
|
YES
|
||||||
|
NO
|
||||||
|
YES
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 110.999 ms
|
||||||
|
|
@ -1,5 +1,2 @@
|
||||||
500 42 168
|
hi
|
||||||
14 42 5
|
hi
|
||||||
|
|
||||||
[code]: 0
|
|
||||||
[time]: 4.26412 ms
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ setup:
|
||||||
test -d build || mkdir -p build
|
test -d build || mkdir -p build
|
||||||
test -d io || mkdir -p io
|
test -d io || mkdir -p io
|
||||||
test -d scripts || mkdir -p scripts
|
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 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
|
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue