more code

This commit is contained in:
Barrett Ruth 2025-01-30 17:06:38 -05:00
parent 7aacde99f4
commit 742bf851a9
149 changed files with 7065 additions and 0 deletions

View file

@ -0,0 +1,9 @@
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false

View file

@ -0,0 +1 @@
#include <bits/stdc++.h>

View file

@ -0,0 +1,139 @@
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
template <typename... Args> void print(string const &str, Args &&...args) {
cout << vformat(str, make_format_args(forward<Args>(args)...));
}
template <typename T> void print(T const &t) { cout << t; }
template <ranges::range T> void print(T const &t) {
if constexpr (is_same_v<T, string> || is_convertible_v<T, char const *>) {
cout << t << '\n';
} else {
for (const auto &e : t) {
cout << e << ' ';
}
cout << '\n';
}
}
template <typename... Args> void println(string const &str, Args &&...args) {
print(str, fo

View file

@ -0,0 +1,193 @@
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
template <typename... Args> void print(string const &str, Args &&...args) {
cout << vformat(str, make_format_args(forward<Args>(args)...));
}
template <typename T> void print(T const &t) { cout << t; }
template <ranges::range T> void print(T const &t) {
if constexpr (is_same_v<T, string> || is_convertible_v<T, char const *>) {
cout << t << '\n';
} else {
for (const auto &e : t) {
cout << e << ' ';
}
cout << '\n';
}
}
template <typename... Args> void println(string const &str, Args &&...args) {
print(str, forward<Args>(args)...);
cout << '\n';
}
template <typename T> void println(T const &t) { print("{}\n", t); }
template <ranges::range T> void println(T const &t) {
print(t);
cout << '\n';
}
void println() { cout << '\n'; }
template <typename T> T max() { return numeric_limits<T>::max(); }
template <typename T> T min() { return numeric_limits<T>::min(); }
constexpr static int MOD = 1e9 + 7;
void solve() {
int n, k, d;
cin >> n >> k >> d;
hashmap<pair<int, int>, int> memo;
auto dp = [&](auto &self, int n, int d) -> int {
if (memo.find({n, d}) != memo.end())
return memo[{n, d}];
if (n == 0)
return d == 0 ? 1 : 0;
ll total = 0;
FOR(i, 1, min(n + 1, k + 1)) {
total = (total + self(self, n - i, i < d ? d : 0)) % MOD;
}
return memo[{n, d}] = total;
};
print(dp(dp, n, d));
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}

View file

@ -0,0 +1,193 @@
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
template <typename... Args> void print(string const &str, Args &&...args) {
cout << vformat(str, make_format_args(forward<Args>(args)...));
}
template <typename T> void print(T const &t) { cout << t; }
template <ranges::range T> void print(T const &t) {
if constexpr (is_same_v<T, string> || is_convertible_v<T, char const *>) {
cout << t << '\n';
} else {
for (const auto &e : t) {
cout << e << ' ';
}
cout << '\n';
}
}
template <typename... Args> void println(string const &str, Args &&...args) {
print(str, forward<Args>(args)...);
cout << '\n';
}
template <typename T> void println(T const &t) { print("{}\n", t); }
template <ranges::range T> void println(T const &t) {
print(t);
cout << '\n';
}
void println() { cout << '\n'; }
template <typename T> T max() { return numeric_limits<T>::max(); }
template <typename T> T min() { return numeric_limits<T>::min(); }
constexpr static int MOD = 1e9 + 7;
void solve() {
int n, k, d;
cin >> n >> k >> d;
hashmap<pair<int, int>, int> memo;
auto dp = [&](auto &self, int n, int d) -> int {
if (memo.find({n, d}) != memo.end())
return memo[{n, d}];
if (n == 0)
return d == 0 ? 1 : 0;
ll total = 0;
FOR(i, 1, min(n + 1, k + 1)) {
total = (total + self(self, n - i, i < d ? d : 0)) % MOD;
}
return memo[{n, d}] = total;
};
print(dp(dp, n, d));
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}

View file

@ -0,0 +1,139 @@
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
template <typename... Args> void print(string const &str, Args &&...args) {
cout << vformat(str, make_format_args(forward<Args>(args)...));
}
template <typename T> void print(T const &t) { cout << t; }
template <ranges::range T> void print(T const &t) {
if constexpr (is_same_v<T, string> || is_convertible_v<T, char const *>) {
cout << t << '\n';
} else {
for (const auto &e : t) {
cout << e << ' ';
}
cout << '\n';
}
}
template <typename... Args> void println(string const &str, Args &&...args) {
print(str, fo

View file

@ -0,0 +1 @@
#include <bits/stdc++.h>

View file

@ -0,0 +1,193 @@
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
template <typename... Args> void print(string const &str, Args &&...args) {
cout << vformat(str, make_format_args(forward<Args>(args)...));
}
template <typename T> void print(T const &t) { cout << t; }
template <ranges::range T> void print(T const &t) {
if constexpr (is_same_v<T, string> || is_convertible_v<T, char const *>) {
cout << t << '\n';
} else {
for (const auto &e : t) {
cout << e << ' ';
}
cout << '\n';
}
}
template <typename... Args> void println(string const &str, Args &&...args) {
print(str, forward<Args>(args)...);
cout << '\n';
}
template <typename T> void println(T const &t) { print("{}\n", t); }
template <ranges::range T> void println(T const &t) {
print(t);
cout << '\n';
}
void println() { cout << '\n'; }
template <typename T> T max() { return numeric_limits<T>::max(); }
template <typename T> T min() { return numeric_limits<T>::min(); }
constexpr static int MOD = 1e9 + 7;
void solve() {
int n, k, d;
cin >> n >> k >> d;
hashmap<pair<int, int>, int> memo;
auto dp = [&](auto &self, int n, int d) -> int {
if (memo.find({n, d}) != memo.end())
return memo[{n, d}];
if (n == 0)
return d == 0 ? 1 : 0;
ll total = 0;
FOR(i, 1, min(n + 1, k + 1)) {
total = (total + self(self, n - i, i < d ? d : 0)) % MOD;
}
return memo[{n, d}] = total;
};
print(dp(dp, n, d));
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}

193
codeforces/431/c.cc Normal file
View file

@ -0,0 +1,193 @@
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define vec vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
template <typename... Args> void print(string const &str, Args &&...args) {
cout << vformat(str, make_format_args(forward<Args>(args)...));
}
template <typename T> void print(T const &t) { cout << t; }
template <ranges::range T> void print(T const &t) {
if constexpr (is_same_v<T, string> || is_convertible_v<T, char const *>) {
cout << t << '\n';
} else {
for (const auto &e : t) {
cout << e << ' ';
}
cout << '\n';
}
}
template <typename... Args> void println(string const &str, Args &&...args) {
print(str, forward<Args>(args)...);
cout << '\n';
}
template <typename T> void println(T const &t) { print("{}\n", t); }
template <ranges::range T> void println(T const &t) {
print(t);
cout << '\n';
}
void println() { cout << '\n'; }
template <typename T> T max() { return numeric_limits<T>::max(); }
template <typename T> T min() { return numeric_limits<T>::min(); }
constexpr static int MOD = 1e9 + 7;
void solve() {
int n, k, d;
cin >> n >> k >> d;
hashmap<pair<int, int>, int> memo;
auto dp = [&](auto self, int n, int d) -> int {
if (memo.find({n, d}) != memo.end())
return memo[{n, d}];
if (n == 0)
return d == 0 ? 1 : 0;
ll total = 0;
FOR(i, 1, min(n + 1, k + 1)) {
total = (total + self(self, n - i, i < d ? d : 0)) % MOD;
}
return memo[{n, d}] = total;
};
print(dp(dp, n, d));
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}

BIN
codeforces/431/c.debug Executable file

Binary file not shown.

1
codeforces/431/c.in Normal file
View file

@ -0,0 +1 @@
4 5 2

1
codeforces/431/c.out Normal file
View file

@ -0,0 +1 @@
7

View file

@ -0,0 +1,5 @@
-std=c++20
-Wall
-Wextra
-Wshadow
-DLOCAL

109
codeforces/431/d.cc Normal file
View file

@ -0,0 +1,109 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

BIN
codeforces/431/d.debug Executable file

Binary file not shown.

0
codeforces/431/d.in Normal file
View file

0
codeforces/431/d.out Normal file
View file

109
codeforces/431/e.cc Normal file
View file

@ -0,0 +1,109 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

BIN
codeforces/431/e.debug Executable file

Binary file not shown.

0
codeforces/431/e.in Normal file
View file

0
codeforces/431/e.out Normal file
View file

View file

@ -0,0 +1,2 @@
BasedOnStyle: Google
AllowShortFunctionsOnASingleLine: Empty

126
codeforces/640/a.cc Normal file
View file

@ -0,0 +1,126 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
int k = 0;
vec<int> summands;
int power = 0;
while (n) {
int digit = n % 10;
if (digit) {
++k;
summands.push_back(static_cast<int>(pow(10, power)) * digit);
}
++power;
n /= 10;
}
cout << k << '\n';
for (auto summand : summands) cout << summand << ' ';
cout << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

6
codeforces/640/a.in Normal file
View file

@ -0,0 +1,6 @@
5
5009
7
9876
10000
10

10
codeforces/640/a.out Normal file
View file

@ -0,0 +1,10 @@
2
9 5000
1
7
4
6 70 800 9000
1
10000
1
10

134
codeforces/640/b.cc Normal file
View file

@ -0,0 +1,134 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
/*
n, k; SUM ai = n, same parity
n odd: k even -> NO; k odd -> YES
n even: k even: odd #s -> NO, only even
*/
int n, k;
cin >> n >> k;
if (k > n) {
NO();
return;
}
if ((n - 2 * (k - 1)) % 2 == 0 && (n - 2 * (k - 1)) > 0) {
YES();
FOR(i, 1, k)
cout << 2 << ' ';
cout << n - 2 * (k - 1) << '\n';
} else if ((n - k + 1) & 1) {
YES();
FOR(i, 1, k)
cout << 1 << ' ';
cout << n - k + 1 << '\n';
} else
NO();
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

9
codeforces/640/b.in Normal file
View file

@ -0,0 +1,9 @@
8
10 3
100 4
8 7
97 2
8 8
3 10
5 3
1000000000 9

13
codeforces/640/b.out Normal file
View file

@ -0,0 +1,13 @@
YES
2 2 6
YES
2 2 2 94
NO
NO
YES
1 1 1 1 1 1 1 1
NO
YES
1 1 3
YES
2 2 2 2 2 2 2 2 999999984

124
codeforces/640/c.cc Normal file
View file

@ -0,0 +1,124 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n, k;
cin >> n >> k;
/*
take n;
n divides n, 2n, 3n, 4n, ...
kth positive integer not divisible by n;
just count ^ : n - 1, n - 1 between each
binary search on the right #;
*/
ll x = k + k / (n - 1);
if (x % n == 0) --x;
println(x);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

7
codeforces/640/c.in Normal file
View file

@ -0,0 +1,7 @@
6
3 7
4 12
2 1000000000
7 97
1000000000 1000000000
2 1

6
codeforces/640/c.out Normal file
View file

@ -0,0 +1,6 @@
10
15
1999999999
113
1000000001
1

View file

@ -0,0 +1,5 @@
-std=c++20
-Wall
-Wextra
-Wshadow
-DLOCAL

139
codeforces/640/d.cc Normal file
View file

@ -0,0 +1,139 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
vec<int> A(n);
for (auto &e : A) cin >> e;
int moves = 1, i = 1, j = sz(A) - 1;
int a = A[0], b = 0;
int prev = a;
while (i <= j) {
int cur = 0;
// bob
if (moves & 1) {
while (i <= j && cur <= prev) {
cur += A[j];
--j;
}
b += cur;
prev = cur;
} else { // alice
while (i <= j && cur <= prev) {
cur += A[i];
++i;
}
a += cur;
prev = cur;
}
++moves;
}
println("{} {} {}", moves, a, b);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

15
codeforces/640/d.in Normal file
View file

@ -0,0 +1,15 @@
7
11
3 1 4 1 5 9 2 6 5 3 5
1
1000
3
1 1 1
13
1 2 3 4 5 6 7 8 9 10 11 12 13
2
2 1
6
1 1 1 1 1 1
7
1 1 1 1 1 1 1

7
codeforces/640/d.out Normal file
View file

@ -0,0 +1,7 @@
6 23 21
1 1000 0
2 1 2
6 45 46
2 2 1
3 4 2
4 4 3

231
codeforces/640/e.cc Normal file
View file

@ -0,0 +1,231 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
#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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
void solve() {
int n;
cin >> n;
vec<int> a(n);
vec<int> freq(n + 1, 0);
for (auto &e : a) {
cin >> e;
++freq[e];
}
int ans = 0;
FOR(i, 0, n) {
int total = 0;
FOR(j, i, n) {
total += a[j];
if (i != j && total <= n) {
ans += freq[total];
freq[total] = 0;
}
}
}
println(ans);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

11
codeforces/640/e.in Normal file
View file

@ -0,0 +1,11 @@
5
9
3 1 4 1 5 9 2 6 5
3
1 1 2
5
1 1 1 1 1
8
8 7 6 5 4 3 2 1
1
1

5
codeforces/640/e.out Normal file
View file

@ -0,0 +1,5 @@
5
1
0
4
0

124
codeforces/640/f.cc Normal file
View file

@ -0,0 +1,124 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n0, n1, n2;
cin >> n0 >> n1 >> n2;
if (n1 == 0) {
char s = n0 ? '0' : '1';
cout << string(max(n0, n2) + 1, s) << '\n';
return;
}
string ans;
FOR(i, 0, n1 + 1)
ans += i & 1 ? '0' : '1';
ans.insert(1, string(n0, '0'));
ans = string(n2, '1') + ans;
println(ans);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

9
codeforces/640/f.in Normal file
View file

@ -0,0 +1,9 @@
8
0 3 4
1 3 5
1 1 1
3 9 3
0 1 0
3 1 2
0 0 3
2 0 0

8
codeforces/640/f.out Normal file
View file

@ -0,0 +1,8 @@
11111010
1111110010
1100
1111000010101010
10
1110000
1111
000

174
codeforces/640/g.cc Normal file
View file

@ -0,0 +1,174 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
/*
1, 4, 2, 5, 3, 6, 9, 7, 10, 8
1: 5, 7, 3, 6 -> pop -> 2, -4, 3
2: 5, 7, 3, 6, 8
3: 3, 7, 9, 6, 8 -> +4, +2, -3, +2
4: 3, -2, 3, -2
1, 4, 2, 5, 3, 7, 9, 6, 8
n = 4 -> 2 4 1 3
+1, +3, -2, +3, -2, +3, +3, -2, +3, -2
*/
if (n < 4) {
println(-1);
return;
}
if (n == 4) {
println("2 4 1 3");
return;
}
vec<int> ans{1};
int prev = 1;
--n;
while (n >= 5) {
for (auto diff : {3, -2, 3, -2, 3}) {
prev += diff;
ans.push_back(prev);
}
n -= 5;
}
vec<int> diff;
switch (n) {
case 1:
ans.pop_back();
ans.pop_back();
diff = {2, -4, 3};
break;
case 2:
ans.pop_back();
ans.pop_back();
diff = {2, -4, 3, 2};
break;
case 3:
ans.pop_back();
diff = {4, 2, -3, 2};
break;
case 4:
diff = {3, -2, 3, -2};
break;
}
for (auto d : diff) ans.push_back(ans[sz(ans) - 1] + d);
for (auto e : ans) cout << e << ' ';
println();
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

8
codeforces/640/g.in Normal file
View file

@ -0,0 +1,8 @@
7
10
2
4
6
7
9
13

7
codeforces/640/g.out Normal file
View file

@ -0,0 +1,7 @@
1 4 2 5 3 6 9 7 10 8
-1
2 4 1 3
1 4 2 5 3 6
1 4 2 5 7 3 6
1 4 2 5 3 7 9 6 8
1 4 2 5 3 6 9 7 10 12 8 11 13

View file

@ -0,0 +1,2 @@
BasedOnStyle: Google
AllowShortFunctionsOnASingleLine: Empty

120
codeforces/923/a.cc Normal file
View file

@ -0,0 +1,120 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
int l = -1, r = -1;
FOR(i, 0, n) {
char c;
cin >> c;
if (l == -1 && c == 'B') l = i;
if (c == 'B') r = i;
}
println(r - l + 1);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

17
codeforces/923/a.in Normal file
View file

@ -0,0 +1,17 @@
8
6
WBBWBW
1
B
2
WB
3
BBW
4
BWWB
6
BWBWWB
6
WWBBWB
9
WBWBWWWBW

24
codeforces/923/a.out Normal file
View file

@ -0,0 +1,24 @@
hi
4
hi
1
hi
1
hi
2
hi
4
hi
6
hi
4
hi
7

231
codeforces/923/b.cc Normal file
View file

@ -0,0 +1,231 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
#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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
void solve() {
int n;
cin >> n;
string ans;
vec<deque<char>> rev(n + 1);
int last_used = -1;
FOR(i, 0, n) {
int a;
cin >> a;
if (a == 0) {
++last_used;
cout << (char(last_used + 'a'));
rev[1].push_back(last_used);
} else {
cout << char(rev[a].front() + 'a');
rev[a + 1].push_back(rev[a].front());
rev[a].pop_front();
}
}
println();
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

11
codeforces/923/b.in Normal file
View file

@ -0,0 +1,11 @@
5
11
0 0 0 1 0 2 0 3 1 1 4
10
0 0 0 0 0 1 0 1 1 0
1
0
8
0 1 2 3 4 5 6 7
8
0 0 0 0 0 0 0 0

5
codeforces/923/b.out Normal file
View file

@ -0,0 +1,5 @@
abcadaeabca
abcdeafbcg
a
aaaaaaaa
abcdefgh

150
codeforces/923/c.cc Normal file
View file

@ -0,0 +1,150 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
bitset<2 * 2 * 100000 + 1> a, b;
void solve() {
int n, m, k;
cin >> n >> m >> k;
// ensure:
// a) all found
// b) <= k / 2 elements in [1,k] from just one arry
int x;
while (n--) {
cin >> x;
if (x > k) continue;
a.set(x);
}
while (m--) {
cin >> x;
if (x > k) continue;
b.set(x);
}
bool all_found = true;
int unique_to_a = 0, unique_to_b = 0;
for (int i = 1; i <= k; ++i) {
if (!a[i] && !b[i]) {
all_found = false;
break;
}
if (a[i] && !b[i]) ++unique_to_a;
if (!a[i] && b[i]) ++unique_to_b;
}
if (all_found && unique_to_a <= k / 2 && unique_to_b <= k / 2)
YES();
else
NO();
a.reset();
b.reset();
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

19
codeforces/923/c.in Normal file
View file

@ -0,0 +1,19 @@
6
6 5 6
2 3 8 5 6 5
1 3 4 10 5
6 5 6
2 3 4 5 6 5
1 3 8 10 3
3 3 4
1 3 5
2 4 6
2 5 4
1 4
7 3 4 4 2
1 4 2
2
6 4 4 2
1 5 2
3
2 2 1 4 3

6
codeforces/923/c.out Normal file
View file

@ -0,0 +1,6 @@
YES
NO
YES
YES
NO
NO

View file

@ -0,0 +1,5 @@
-std=c++20
-Wall
-Wextra
-Wshadow
-DLOCAL

136
codeforces/923/d.cc Normal file
View file

@ -0,0 +1,136 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
vec<int> a(n);
vec<int> p(n, -1);
cin >> a[0];
FOR(i, 1, n) {
cin >> a[i];
p[i] = p[i - 1];
if (a[i] != a[i - 1]) p[i] = i - 1;
}
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
--l;
--r;
int i = r;
int j = p[r];
if (j < l) i = -2, j = -2;
println("{} {}", i + 1, j + 1);
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

40
codeforces/923/d.in Normal file
View file

@ -0,0 +1,40 @@
5
5
1 1 2 1 1
3
1 5
1 2
1 3
6
30 20 20 10 10 20
5
1 2
2 3
2 4
2 6
3 5
4
5 2 3 4
4
1 2
1 4
2 3
2 4
5
1 4 3 2 4
5
1 5
2 4
3 4
3 5
4 5
5
2 3 1 4 2
7
1 2
1 4
1 5
2 4
2 5
3 5
4 5

24
codeforces/923/d.out Normal file
View file

@ -0,0 +1,24 @@
5 3
-1 -1
3 2
2 1
-1 -1
4 3
6 5
5 3
2 1
4 3
3 2
4 3
5 4
4 3
4 3
5 4
5 4
2 1
4 3
5 4
4 3
5 4
5 4
5 4

BIN
codeforces/923/exe Executable file

Binary file not shown.

110
codeforces/923/j.cc Normal file
View file

@ -0,0 +1,110 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() {
cout << "YES\n";
}
void NO() {
cout << "NO\n";
}
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
aknf;
kdsafkjadsfjadsfj
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

0
codeforces/923/j.in Normal file
View file

8
codeforces/923/j.out Normal file
View file

@ -0,0 +1,8 @@
j.cc: In function void solve():
j.cc:72:3: error: aknf was not declared in this scope
72 | aknf;kdsafkjadsfjadsfj
| ^~~~
j.cc:72:8: error: kdsafkjadsfjadsfj was not declared in this scope
72 | aknf;kdsafkjadsfjadsfj
| ^~~~~~~~~~~~~~~~~
zsh:1: permission denied: /tmp/tmp.yMxI36SPlf

86
codeforces/923/k.cc Normal file
View file

@ -0,0 +1,86 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args> void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
// make_format_args binds arguments to const
std::make_format_args(args...));
}
template <typename T> void print(T const &t) { std::cout << t; }
template <std::ranges::range T> void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T> void println(T const &t) { print("{}\n", t); }
template <std::ranges::range T> void println(T const &t) { cout << t << '\n'; }
void println() { std::cout << '\n'; }
template <typename T> T MAX() { return std::numeric_limits<T>::max(); }
template <typename T> T MIN() { return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#define FOR(a, b, c) for (int a = b; a < c; ++a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(a, b) uniform_int_distribution(a, b)(rng)
void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

0
codeforces/923/k.in Normal file
View file

0
codeforces/923/k.out Normal file
View file

View file

@ -0,0 +1,2 @@
BasedOnStyle: Google
AllowShortFunctionsOnASingleLine: Empty

67
codeforces/974/a.cc Normal file
View file

@ -0,0 +1,67 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n, k;
cin >> n >> k;
vec<int> people(n);
for (auto &e : people) cin >> e;
int ans = 0, robin = 0;
for (auto amount : people) {
if (amount >= k)
robin += amount;
else if (robin > 0 && amount == 0) {
--robin;
++ans;
}
}
cout << ans << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

BIN
codeforces/974/a.debug Executable file

Binary file not shown.

9
codeforces/974/a.in Normal file
View file

@ -0,0 +1,9 @@
4
2 2
2 0
3 2
3 0 0
6 2
0 3 0 0 0 0
2 5
5 4

4
codeforces/974/a.out Normal file
View file

@ -0,0 +1,4 @@
1
2
3
0

112
codeforces/974/b.cc Normal file
View file

@ -0,0 +1,112 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(
str,
// make_format_args binds arguments to const
str, std::make_format_args(static_cast<Args const &>(args)...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
int n, k;
cin >> n >> k;
int overlaps = k - 1;
if (n & 1) {
// need odd # odds in overlaps
int odd_count = floor(overlaps / 2);
cout << (odd_count & 1 ? "YES" : "NO");
} else {
int odd_count = ceil(overlaps / 2);
cout << (odd_count & 1 ? "NO" : "YES");
}
cout << '\n';
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

BIN
codeforces/974/b.debug Executable file

Binary file not shown.

6
codeforces/974/b.in Normal file
View file

@ -0,0 +1,6 @@
5
1 1
2 1
2 2
3 2
4 4

5
codeforces/974/b.out Normal file
View file

@ -0,0 +1,5 @@
NO
YES
YES
NO
NO

114
codeforces/974/c.cc Normal file
View file

@ -0,0 +1,114 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(
str,
// make_format_args binds arguments to const
str, std::make_format_args(static_cast<Args const &>(args)...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
void solve() {
ll n;
cin >> n;
vec<int> people(n);
ll total = 0;
for (auto &e : people) {
cin >> e;
total += e;
};
sort(all(people));
if (n >= 3) {
cout << max(static_cast<ll>(0), 1 + people[n / 2] * 2 * n - total);
} else
cout << -1;
cout << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

13
codeforces/974/c.in Normal file
View file

@ -0,0 +1,13 @@
6
1
2
2
2 19
3
1 3 20
4
1 2 3 4
5
1 2 3 4 5
6
1 2 1 1 1 25

6
codeforces/974/c.out Normal file
View file

@ -0,0 +1,6 @@
-1
-1
0
15
16
0

View file

@ -0,0 +1,5 @@
-std=c++20
-Wall
-Wextra
-Wshadow
-DLOCAL

130
codeforces/974/d.cc Normal file
View file

@ -0,0 +1,130 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(
str,
// make_format_args binds arguments to const
str, std::make_format_args(static_cast<Args const &>(args)...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
static constexpr int MOD = 1e9 + 7;
#define FOR(a, b, c) for (int a = b; a < c; ++a)
void solve() {
int n, d, k;
cin >> n >> d >> k;
vec<int> start(n + 1);
vec<int> end(n + 1);
while (k--) {
int l, r;
cin >> l >> r;
++start[l];
++end[r];
}
// prefix
FOR(i, 1, n + 1) {
start[i] += start[i - 1];
end[i] += end[i - 1];
}
int brother = MIN<int>(), mother = MAX<int>();
int brother_day = 0, mother_day = 0;
FOR(i, 0, n - d + 1) {
if (start[i + d] - end[i] > brother) {
brother = start[i + d] - end[i];
brother_day = i;
}
if (start[i + d] - end[i] < mother) {
mother = start[i + d] - end[i];
mother_day = i;
}
}
cout << (brother_day + 1) << ' ' << (mother_day + 1) << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

20
codeforces/974/d.in Normal file
View file

@ -0,0 +1,20 @@
6
2 1 1
1 2
4 1 2
1 2
2 4
7 2 3
1 2
1 3
6 7
5 1 2
1 2
3 5
9 2 1
2 8
9 2 4
7 9
4 8
1 3
2 3

6
codeforces/974/d.out Normal file
View file

@ -0,0 +1,6 @@
1 1
2 1
1 4
1 1
1 1
3 4

229
codeforces/974/h.cc Normal file
View file

@ -0,0 +1,229 @@
#include <bits/stdc++.h>
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
template <typename... Args>
void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(
str,
// make_format_args binds arguments to const
str, std::make_format_args(static_cast<Args const &>(args)...));
}
template <typename T>
void print(T const &t) {
std::cout << t;
}
template <std::ranges::range T>
void print(T const &t) {
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T>
void println(T const &t) {
print("{}\n", t);
}
template <std::ranges::range T>
void println(T const &t) {
cout << t << '\n';
}
void println() {
std::cout << '\n';
}
template <typename T>
T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
T MIN() {
return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
#define FOR(a, b, c) for (int a = b; a < c; ++a)
static constexpr int MOD = 1e9 + 7;
#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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distrib(0, MAX<int>());
void solve() {
int n, q;
cin >> n >> q;
vector<int> prefix_hash_xor(n);
// map index in a -> hash
hashmap<int, int> hm;
FOR(i, 0, n) {
cin >> prefix_hash_xor[i];
prefix_hash_xor[i] ^= (i ? prefix_hash_xor[i - 1] : 0);
}
while (q--) {
int l, r;
cin >> l >> r;
--l;
--r;
bool even_each =
(prefix_hash_xor[r] ^ (l ? prefix_hash_xor[l - 1] : 0)) == 0;
cout << (even_each ? "YES" : "NO") << '\n';
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

11
codeforces/974/h.in Normal file
View file

@ -0,0 +1,11 @@
2
3 3
1 2 2
1 2
1 3
2 3
5 3
2 1 2 1 1
1 2
1 3
4 5

6
codeforces/974/h.out Normal file
View file

@ -0,0 +1,6 @@
NO
NO
YES
NO
NO
YES

45
codeforces/984/a.cc Normal file
View file

@ -0,0 +1,45 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
#ifdef LOCAL
#define dbg(x) cerr << #x << " = " << (x) << '\n'
#else
#define dbg(x)
#endif
void solve() {
int n;
cin >> n;
vector<int> notes(n, 0);
for (auto &x : notes)
cin >> x;
for (int i = 1; i < notes.size(); ++i) {
auto diff = abs(notes[i] - notes[i - 1]);
if (!(diff == 5 || diff == 7)) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

17
codeforces/984/a.in Normal file
View file

@ -0,0 +1,17 @@
8
2
114 109
2
17 10
3
76 83 88
8
38 45 38 80 85 92 99 106
5
63 58 65 58 65
8
117 124 48 53 48 43 54 49
5
95 102 107 114 121
10
72 77 82 75 70 75 68 75 68 75

54
codeforces/984/b.cc Normal file
View file

@ -0,0 +1,54 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
#ifdef LOCAL
#define dbg(x) cerr << #x << " = " << (x) << '\n'
#else
#define dbg(x)
#endif
#define MAX_K 2 * 100000
// clearing/resetting vector
// clean way for x^n; exppow
// sorting in orders
// totally misread: test case time *
// how does time work???? per-test case... or
void solve() {
int n, k;
cin >> n >> k;
vector<int> brand_to_cost(k + 1, 0);
for (int i = 0; i < k; ++i) {
int b, c;
cin >> b >> c;
brand_to_cost[b] += c;
}
sort(all(brand_to_cost), std::greater<int>{});
std::cout << accumulate(brand_to_cost.begin(),
brand_to_cost.begin() + min(n, sz(brand_to_cost)),
0LL)
<< '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

14
codeforces/984/b.in Normal file
View file

@ -0,0 +1,14 @@
4
3 3
2 6
2 7
1 15
1 3
2 6
2 7
1 15
6 2
1 7
2 5
190000 1
1 1000

0
codeforces/984/b.out Normal file
View file

76
codeforces/984/c.cc Normal file
View file

@ -0,0 +1,76 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
// variable iterator macro needed
// NOTE: can prob optimize by sorting queries
// fix matchparen highlight
// NOTE: didn't realize queries are independent (bruh)
void solve() {
string s;
cin >> s;
auto valid = [&](int i) -> bool {
return i >= 0 && i < sz(s) - 3 && s[i] == '1' && s[i + 1] == '1' &&
s[i + 2] == '0' && s[i + 3] == '0';
};
int count = 0;
for (int i = 0; i < sz(s); ++i) {
if (valid(i)) {
++count;
}
}
int q;
cin >> q;
for (int _ = 0; _ < q; _++) {
int i;
char v;
cin >> i >> v;
--i;
if (s[i] != v) {
bool left = false;
for (int j = i - 3; j <= i; ++j) {
if (valid(j)) {
left = true;
break;
}
}
s[i] = v;
bool right = false;
for (int j = i - 3; j <= i; ++j) {
if (valid(j)) {
right = true;
break;
}
}
count += (right - left);
}
cout << (count > 0 ? "YES" : "NO") << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

24
codeforces/984/c.in Normal file
View file

@ -0,0 +1,24 @@
4
100
4
1 1
2 0
2 0
3 1
1100000
3
6 1
7 1
4 1
111010
4
1 1
5 0
4 1
5 0
0100
4
3 1
1 1
2 0
2 1

15
codeforces/984/c.out Normal file
View file

@ -0,0 +1,15 @@
NO
NO
NO
NO
YES
YES
NO
NO
YES
YES
YES
NO
NO
NO
NO

93
codeforces/984/d.cc Normal file
View file

@ -0,0 +1,93 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
#ifdef LOCAL
#define dbg(x) cerr << #x << " = " << (x) << '\n'
#else
#define dbg(x)
#endif
constexpr auto _1543 = "1543";
int find_1543(const string &layer) {
if (sz(layer) < 4) {
return 0;
}
string extended = layer + layer.substr(0, 3);
int count = 0;
for (int i = 0; i < sz(layer); ++i) {
bool found = true;
for (int j = 0; j < 4; j++) {
if (extended[i + j] != _1543[j]) {
found = false;
break;
}
}
count += found;
}
return count;
}
string layer(const vector<string> &carpet, int n, int m, int i) {
int top = i, bot = n - 1 - i, l = i, r = m - 1 - i;
string pattern;
for (int c = l; c <= r; c++) {
pattern.push_back(carpet[top][c]);
}
for (int row = top + 1; row < bot; row++) {
pattern.push_back(carpet[row][r]);
}
if (bot > top) {
for (int c = r; c >= l; c--) {
pattern.push_back(carpet[bot][c]);
}
}
if (l < r) {
for (int r = bot - 1; r > top; r--) {
pattern.push_back(carpet[r][l]);
}
}
return pattern;
}
void solve() {
int n, m;
cin >> n >> m;
vector<string> carpet(n);
for (auto &x : carpet) {
cin >> x;
}
long long ans = 0;
const int LAYER_COUNT = min(n, m) / 2;
for (int i = 0; i < LAYER_COUNT; ++i) {
string ring = layer(carpet, n, m, i);
ans += find_1543(ring);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

31
codeforces/984/d.in Normal file
View file

@ -0,0 +1,31 @@
8
2 4
1543
7777
2 4
7154
8903
2 4
3451
8888
2 2
54
13
2 2
51
43
2 6
432015
512034
4 4
5431
1435
5518
7634
6 4
5432
1152
4542
2432
2302
5942

0
codeforces/984/d.out Normal file
View file

64
codeforces/984/e.cc Normal file
View file

@ -0,0 +1,64 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
void solve() {
int n, k, q;
cin >> n >> k >> q;
vector<vector<int>> b(k + 1, vector<int>(n + 1, 0));
int v;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) {
cin >> v;
b[j][i] = b[j][i - 1] | v;
}
}
while (q--) {
int m;
cin >> m;
int l = 0, r = n - 1;
while (m--) {
int R, v;
char c;
cin >> R;
cin >> c;
cin >> v;
if (c == '<') {
int i = distance(b[R].begin() + 1, lower_bound(all(b[R]), v)) - 1;
r = min(r, i);
} else {
int i = distance(b[R].begin() + 1, upper_bound(all(b[R]), v));
l = max(l, i);
}
}
if (l <= r) {
cout << l + 1 << '\n';
} else {
cout << -1 << '\n';
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// int t;
// cin >> t;
// while (t--) {
solve();
// }
return 0;
}

16
codeforces/984/e.in Normal file
View file

@ -0,0 +1,16 @@
3 4 4
1 3 5 9
4 6 5 3
2 1 2 7
3
1 > 4
2 < 8
1 < 6
2
1 < 8
2 > 8
1
3 > 5
2
4 > 8
1 < 8

4
codeforces/984/e.out Normal file
View file

@ -0,0 +1,4 @@
2
-1
3
1

View file

@ -0,0 +1,188 @@
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
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
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
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
template <typename... Args> void print(std::string const &str, Args &&...args) {
std::cout << std::vformat(str,
std::make_format_args(std::forward<Args>(args)...));
}
template <typename T> void print(T const &t) { std::cout << t; }
template <std::ranges::range T> void print(T const &t) {
if constexpr (std::is_same_v<T, string> ||
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 println(std::string const &str, Args &&...args) {
print(str, std::forward<Args>(args)...);
cout << '\n';
}
template <typename T> void println(T const &t) { print("{}\n", t); }
template <std::ranges::range T> void println(T const &t) { cout << t << '\n'; }
void println() { std::cout << '\n'; }
template <typename T> T MAX() { return std::numeric_limits<T>::max(); }
template <typename T> T MIN() { return 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 rall(x) (r).rbegin(), (x).rend()
#define sz(x) static_cast<int>((x).size())
#ifdef LOCAL
#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n";
#else
#define dbg(x)
#endif
constexpr static int MOD = 1e9 + 7;
void solve() {
string s;
cin >> s;
for (int i = 1; i < s.size(); ++i) {
if (s[i] == '0')
continue;
int j = i;
while (j >= 1 && s[j] - 1 > s[j - 1]) {
--s[j];
swap(s[j], s[-1]);
--j;
}
}
println(s);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}

29
codeforces/991/buf Normal file
View file

@ -0,0 +1,29 @@
void solve() {
stGCD.clear();
int n, q; cin >> n >> q;
vector<int> a(n);
for (int &x : a) cin >> x;
vector<int> b;
for (int i = 1; i < n; i++)
b.push_back(abs(a[i - 1] - a[i]));
stGCD.resize(LOGN, vector<int>(b.size(), 1));
for (int i = 0; i < b.size(); i++)
stGCD[0][i] = b[i];
for (int i = 1; i < LOGN; i++)
for (int j = 0; j + (1 << (i - 1)) < b.size(); j++)
stGCD[i][j] = __gcd(stGCD[i - 1][j], stGCD[i - 1][j + (1 << (i - 1))]);
while (q--) {
int l, r; cin >> l >> r;
if (l == r) {
cout << 0 << " ";
continue;
}
l--; r -= 2;
int gcd = get_gcd(l, r);
cout << gcd << " ";
}
}

Some files were not shown because too many files have changed in this diff Show more