feat(cf/895): nonlazy prop soln

This commit is contained in:
Barrett Ruth 2025-03-27 15:02:09 -04:00
parent 6c16185126
commit 94383fbaf7
99 changed files with 4536 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

8
codeforces/1009/.clangd Normal file
View file

@ -0,0 +1,8 @@
CompileFlags:
Add:
- -Wall
- -Wextra
- -Wpedantic
- -Wshadow
- -DLOCAL
- -Wno-unknown-pragmas

83
codeforces/1009/a.cc Normal file
View file

@ -0,0 +1,83 @@
#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> [[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T> [[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T> [[nodiscard]] static T sc(auto &&x) {
return static_cast<T>(x);
}
template <typename T> [[nodiscard]] static T sz(auto &&x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() { prln("NO"); }
inline static void YES() { prln("YES"); }
using ll = long long;
using ld = long double;
template <typename T> using ve = std::vector<T>;
template <typename T, size_t N> using ar = std::array<T, N>;
template <typename T1, typename T2> using pa = std::pair<T1, T2>;
template <typename... Ts> using tu = std::tuple<Ts...>;
template <typename... Ts> using dq = std::deque<Ts...>;
template <typename... Ts> using qu = std::queue<Ts...>;
template <typename... Ts> using pq = std::priority_queue<Ts...>;
template <typename... Ts> using st = std::stack<Ts...>;
auto lb = [](auto... args) { return std::lower_bound(args...); };
auto ub = [](auto... args) { return std::upper_bound(args...); };
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
int l, r, d, u;
cin >> l >> r >> d >> u;
if (l == r && u == d && l == u) {
YES();
} else {
NO();
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

3
codeforces/1009/a.in Normal file
View file

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

5
codeforces/1009/a.out Normal file
View file

@ -0,0 +1,5 @@
YES
NO
[code]: 0
[time]: 14.5509 ms

109
codeforces/1009/b.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 T>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
/*
idea: choose min2 and replace w/ a + b - 1
*/
int n;
cin >> n;
ve<int> a(n);
for (auto& e : a)
cin >> e;
sort(all(a));
for (int i = 1; i < n; ++i) {
a[i] = a[i] + a[i - 1] - 1;
}
prln("{}", a[n - 1]);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

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

@ -0,0 +1,9 @@
4
1
10
3
998 244 353
5
1 2 3 4 5
9
9 9 8 2 4 4 3 5 3

7
codeforces/1009/b.out Normal file
View file

@ -0,0 +1,7 @@
10
1593
11
39
[code]: 0
[time]: 13.7115 ms

125
codeforces/1009/c.cc Normal file
View file

@ -0,0 +1,125 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
ll x;
cin >> x;
/*
sl x, y, x ^ y
O(1) to check with a guess
binary search?
a > b
x fixed, choose some y < x
x, y = 1 -> x, 1, x + 1 OR x, 1, x - 1
x, y = 2 -> x, 2, x + 2 OR x, 2, x - 2
v more than one differing bit
x + y > x ^ y
x + x ^ y > y
y + x ^ y > x
101010101100
y = x / 2
x + y > z
x + z > y
y + z > x
*/
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

8
codeforces/1009/c.in Normal file
View file

@ -0,0 +1,8 @@
7
5
2
6
3
69
4
420

0
codeforces/1009/c.out Normal file
View file

View file

@ -0,0 +1,6 @@
-Wall
-Wextra
-Wpedantic
-Wshadow
-DLOCAL
-std=c++23

214
codeforces/1009/d.cc Normal file
View file

@ -0,0 +1,214 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto &&x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto &&x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
#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 = null_type>
using hashtable = 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>>;
#endif
#ifdef PB_DS_TREE_POLICY_HPP
template <typename T>
using multitree = 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, m;
cin >> n >> m;
ve<pa<ll, ll>> circles(n);
for (int i = 0; i < n; ++i) {
cin >> circles[i].ff;
}
for (int i = 0; i < n; ++i) {
cin >> circles[i].ss;
}
hashtable<ll, ll> f;
for (auto &[c_i, r_i] : circles) {
for (ll x = c_i - r_i; x <= c_i + r_i; ++x) {
f[x] = max(f[x], (ll)sqrtl(r_i * r_i - (x - c_i) * (x - c_i)));
}
}
prln("{}", accumulate(all(f), 0, [](int x, auto const &p) {
return x + 2 * p.second + 1;
}));
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

13
codeforces/1009/d.in Normal file
View file

@ -0,0 +1,13 @@
4
2 3
0 0
1 2
2 3
0 2
1 2
3 3
0 2 5
1 1 1
4 8
0 5 10 15
2 2 2 2

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

@ -0,0 +1,7 @@
13
16
14
52
[code]: 0
[time]: 13.6807 ms

View file

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

8
codeforces/1013/.clangd Normal file
View file

@ -0,0 +1,8 @@
CompileFlags:
Add:
- -Wall
- -Wextra
- -Wpedantic
- -Wshadow
- -DLOCAL
- -Wno-unknown-pragmas

116
codeforces/1013/a.cc Normal file
View file

@ -0,0 +1,116 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto &&x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto &&x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
// make 01032025
int n;
cin >> n;
ve<int> a(n);
for (auto &e : a)
cin >> e;
ve<int> freqs(10);
int res = 0;
int i;
for (i = 0; i < n; ++i) {
++freqs[a[i]];
if (freqs[1] >= 1 && freqs[0] >= 3 && freqs[3] >= 1 && freqs[2] >= 2 &&
freqs[5] >= 1) {
res = i + 1;
break;
}
}
prln("{}", res);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

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

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

7
codeforces/1013/a.out Normal file
View file

@ -0,0 +1,7 @@
9
0
8
15
[code]: 0
[time]: 12.8527 ms

47
codeforces/1013/a.py Normal file
View file

@ -0,0 +1,47 @@
def can_arrange_columns(x, m, n):
"""
Determine if x columns can be arranged in m columns with non-adjacent batches
where each batch is <= n columns.
Args:
x (int): Total number of columns to arrange
m (int): Total available column slots
n (int): Maximum batch size
Returns:
bool: True if arrangement is possible, False otherwise
Time complexity: O(1)
Space complexity: O(1)
"""
# If x is 0, it's always possible
if x == 0:
return True
# Calculate the maximum number of batches that can be placed
# Each batch requires space for cols + an empty col (except potentially the last)
max_gaps = (m + 1) // (n + 1)
# Maximum total columns that can be placed
max_columns = max_gaps * n
# Check if we can fit all x columns
return x <= max_columns
# Comprehensive test cases
def test_column_arrangement():
# Test cases
test_cases = [
# x, m, n, expected_result
(3, 5, 2, True)
]
for x, m, n, expected in test_cases:
result = can_arrange_columns(x, m, n)
print(f"x={x}, m={m}, n={n}: {result} (Expected: {expected})")
assert result == expected, f"Failed for x={x}, m={m}, n={n}"
print("All test cases passed!")
# Run the tests
test_column_arrangement()

122
codeforces/1013/b.cc Normal file
View file

@ -0,0 +1,122 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
int n;
ll x;
cin >> n >> x;
ve<ll> a(n);
for (auto& e : a)
cin >> e;
sort(rall(a));
int res = 0;
int i = 0;
while (i < n) {
ll minimum = a[i];
ll seen = 1;
++i;
while (i < n && minimum * seen < x) {
minimum = min(minimum, a[i]);
++seen;
++i;
}
if (minimum * seen >= x) {
++res;
}
}
prln("{}", res);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

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

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

8
codeforces/1013/b.out Normal file
View file

@ -0,0 +1,8 @@
4
0
4
2
1
[code]: 0
[time]: 5.56087 ms

109
codeforces/1013/c.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 T>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
int n;
cin >> n;
if (n % 2 == 0) {
prln("-1");
return;
}
ve<int> ans;
for (int i = 1; i <= n; i += 2)
pr("{} ", i);
for (int i = 2; i <= n; i += 2)
pr("{} ", i);
prln();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

4
codeforces/1013/c.in Normal file
View file

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

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

@ -0,0 +1,6 @@
-1
1 3 5 2 4
1 3 2
[code]: 0
[time]: 12.7263 ms

View file

@ -0,0 +1,6 @@
-Wall
-Wextra
-Wpedantic
-Wshadow
-DLOCAL
-std=c++23

124
codeforces/1013/d.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 T>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
ll n, m, k;
cin >> n >> m >> k;
ll to_place = ceill(sc<ld>(k) / n);
auto can = [&](ll group_size) {
ll groups = to_place / group_size;
ll extra = to_place - groups * group_size;
if (extra) {
return groups * group_size + extra + groups <= m;
}
return groups * group_size + groups - 1 <= m;
};
ll l = 1, r = k;
while (l <= r) {
ll group_size = l + (r - l) / 2;
if (can(group_size)) {
r = group_size - 1;
} else {
l = group_size + 1;
}
}
prln("{}", l);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

6
codeforces/1013/d.in Normal file
View file

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

8
codeforces/1013/d.out Normal file
View file

@ -0,0 +1,8 @@
2
1
1
4
2
[code]: 0
[time]: 12.7797 ms

124
codeforces/1013/e.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 T>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
constexpr int MAX_N = 1e7 + 1;
bitset<MAX_N> prime;
ve<int> P;
void sieve() {
prime.set();
prime[0] = prime[1] = 0;
for (ll a = 2; a < MAX_N; ++a) {
if (prime[a]) {
P.eb(a);
for (ll b = a * a; b < MAX_N; b += a) {
prime[b] = 0;
}
}
}
}
void solve() {
int n;
cin >> n;
ll ans = 0;
for (ll p : P) {
if (p > n) {
break;
}
ans += n / p;
}
prln("{}", ans);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
sieve();
while (t--) {
solve();
}
return 0;
}
// }}

5
codeforces/1013/e.in Normal file
View file

@ -0,0 +1,5 @@
4
5
10
34
10007

7
codeforces/1013/e.out Normal file
View file

@ -0,0 +1,7 @@
4
11
49
24317
[code]: 0
[time]: 312.926 ms

181
codeforces/1013/f.cc Normal file
View file

@ -0,0 +1,181 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
constexpr static ll MOD = 998244353;
void solve() {
int n, m;
ld d;
cin >> n >> m >> d;
ll d_squared = ll(d * d + 0.5); // Round to nearest integer
auto dist = [](pair<ll, ll> p1, pair<ll, ll> p2) {
return (p1.first - p2.first) * (p1.first - p2.first) +
(p1.second - p2.second) * (p1.second - p2.second);
};
vector<string> grid(n);
for (int i = 0; i < n; ++i) {
cin >> grid[i];
}
reverse(grid.begin(), grid.end());
vector<vector<pair<ll, ll>>> holds(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (grid[i][j] == 'X') {
holds[i].emplace_back(j, i);
}
}
}
// Check if starting level has holds
if (holds[0].empty()) {
cout << "0\n";
return;
}
vector<ll> prev(holds[0].size(), 1);
for (int level = 1; level < n; ++level) {
if (holds[level].empty()) {
cout << "0\n";
return;
}
vector<ll> dp1(holds[level].size(), 0);
vector<ll> dp2(holds[level].size(), 0);
// First pass: transition from previous level
int l = 0, r = 0;
ll total = 0;
for (int i = 0; i < holds[level].size(); ++i) {
auto& h = holds[level][i];
// Expand r to include holds with dist <= d_squared
while (r < prev.size() && dist(holds[level - 1][r], h) <= d_squared) {
total = (total + prev[r]) % MOD;
r++;
}
// Shrink l to exclude holds with dist > d_squared
while (l < r && dist(holds[level - 1][l], h) > d_squared) {
total = (total - prev[l] + MOD) % MOD;
l++;
}
dp1[i] = total;
}
// Second pass: same-level transitions (pairs)
l = 0, r = 0;
total = 0;
for (int i = 0; i < holds[level].size(); ++i) {
auto& h = holds[level][i];
// Expand r to include holds with dist <= d_squared
while (r < holds[level].size() && dist(holds[level][r], h) <= d_squared) {
total = (total + dp1[r]) % MOD;
r++;
}
// Shrink l to exclude holds with dist > d_squared
while (l < r && dist(holds[level][l], h) > d_squared) {
total = (total - dp1[l] + MOD) % MOD;
l++;
}
// Subtract dp1[i] to avoid self-pairing
dp2[i] = (total - dp1[i] + MOD) % MOD;
}
// Combine dp1 and dp2
for (int i = 0; i < holds[level].size(); ++i) {
dp1[i] = (dp1[i] + dp2[i]) % MOD;
}
prev = dp1;
}
ll ans = accumulate(prev.begin(), prev.end(), 0LL) % MOD;
cout << ans << "\n";
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

13
codeforces/1013/f.in Normal file
View file

@ -0,0 +1,13 @@
3
3 4 1
XX#X
#XX#
#X#X
3 4 2
XX#X
#XX#
#X#X
3 1 3
X
X
#

6
codeforces/1013/f.out Normal file
View file

@ -0,0 +1,6 @@
2
30
0
[code]: 0
[time]: 6.79278 ms

View file

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

8
codeforces/886/.clangd Normal file
View file

@ -0,0 +1,8 @@
CompileFlags:
Add:
- -Wall
- -Wextra
- -Wpedantic
- -Wshadow
- -DLOCAL
- -Wno-unknown-pragmas

84
codeforces/886/a.cc Normal file
View file

@ -0,0 +1,84 @@
#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> [[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T> [[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T> [[nodiscard]] static T sc(auto &&x) {
return static_cast<T>(x);
}
template <typename T> [[nodiscard]] static T sz(auto &&x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() { prln("NO"); }
inline static void YES() { prln("YES"); }
using ll = long long;
using ld = long double;
template <typename T> using ve = std::vector<T>;
template <typename T, size_t N> using ar = std::array<T, N>;
template <typename T1, typename T2> using pa = std::pair<T1, T2>;
template <typename... Ts> using tu = std::tuple<Ts...>;
template <typename... Ts> using dq = std::deque<Ts...>;
template <typename... Ts> using qu = std::queue<Ts...>;
template <typename... Ts> using pq = std::priority_queue<Ts...>;
template <typename... Ts> using st = std::stack<Ts...>;
auto lb = [](auto... args) { return std::lower_bound(args...); };
auto ub = [](auto... args) { return std::upper_bound(args...); };
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
// start 16:03
void solve() {
ve<int> a(3);
for (auto &e : a)
cin >> e;
sort(all(a));
if (a[1] + a[2] >= 10)
YES();
else
NO();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

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

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

116
codeforces/886/b.cc Normal file
View file

@ -0,0 +1,116 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
int n;
cin >> n;
ve<pa<int, int>> responses(n);
for (int i = 0; i < n; ++i) {
cin >> responses[i].ff >> responses[i].ss;
}
// didn't read problem
int best = MIN<int>();
int ans;
for (int i = 0; i < n; ++i) {
if (responses[i].ff <= 10) {
if (responses[i].ss > best) {
best = responses[i].ss;
ans = i;
}
}
}
prln("{}", ans + 1);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

13
codeforces/886/b.in Normal file
View file

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

6
codeforces/886/b.out Normal file
View file

@ -0,0 +1,6 @@
4
3
1
[code]: 0
[time]: 6.05655 ms

120
codeforces/886/c.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 T>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
// was a bit uncertain - didn't notice that you can literally just do this
// (the second solution was my actual first one)
char c;
for (int i = 0; i < 8 * 8; ++i) {
cin >> c;
if (c != '.')
pr("{}", c);
}
prln();
// ve<string> grid(8);
// for (int i = 0; i < 8; ++i) {
// cin >> grid[i];
// }
//
//
// string ans;
// for (int r = 0; r < 8; ++r) {
// for (int c = 0; c < 8; ++c) {
// if (grid[r][c] != '.') {
// ans.pb(grid[r][c]);
// }
// }
// }
// prln("{}", ans);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

41
codeforces/886/c.in Normal file
View file

@ -0,0 +1,41 @@
5
........
........
........
........
...i....
........
........
........
........
.l......
.o......
.s......
.t......
........
........
........
........
........
........
........
......t.
......h.
......e.
........
........
........
........
........
.......g
.......a
.......m
.......e
a.......
a.......
a.......
a.......
a.......
a.......
a.......
a.......

8
codeforces/886/c.out Normal file
View file

@ -0,0 +1,8 @@
i
lost
the
game
aaaaaaaa
[code]: 0
[time]: 13.4587 ms

View file

@ -0,0 +1,6 @@
-Wall
-Wextra
-Wpedantic
-Wshadow
-DLOCAL
-std=c++23

124
codeforces/886/d.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 T>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
int n, k;
cin >> n >> k;
ve<ll> d(n);
for (auto& e : d)
cin >> e;
int keep = 0;
sort(all(d));
// too long, still don't know HOW, but invariants/problem i'd done before
// definitely help
// walking thru/specific logic help
// kept fucking around and not answering the problem
// common thing: "let's read in input before we think about it"
// NO - think then code, that's just procrastinating the problem
int start = 0;
for (int i = 1; i < n; ++i) {
if (d[i] - d[i - 1] > k) {
keep = max(keep, i - start);
start = i;
}
}
keep = max(keep, n - start);
prln("{}", n - keep);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

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

@ -0,0 +1,15 @@
7
5 1
1 2 4 5 6
1 2
10
8 3
17 3 1 20 12 5 17 12
4 2
2 4 6 8
5 3
2 3 19 10 8
3 4
1 10 5
8 1
8 3 1 4 5 10 7 3

10
codeforces/886/d.out Normal file
View file

@ -0,0 +1,10 @@
2
0
5
0
3
1
4
[code]: 0
[time]: 6.87933 ms

150
codeforces/886/e.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 T>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
ll n, c;
cin >> n >> c;
ll sum = 0, sumsq = 0;
ll s;
for (int i = 0; i < n; ++i) {
cin >> s;
sum += s;
sumsq += s * s;
}
ld C = sumsq - c;
ld A = 4 * n;
// NOTE: tbh, look back at solutions,m not sure what went exactly wrong here.
// most definitely just not taking my time
// NOTE: didn't check WHY round down/why is this right, just that it *looked* right in the examples
// this logic is a surefire way to skip certainty and absolutely confuse yourself
ld B = 4 * sum;
ll root = (-B + sqrtl(B * B - 4 * A * C)) / (2 * A);
prln("{}", root);
// NOTE: tbh, look back at solutions,m not sure what went exactly wrong here.
// most definitely just not taking my time
// NOTE: didn't check WHY round down/why is this right, just that it *looked* right in the examples
// this logic is a surefire way to skip certainty and absolutely confuse yourself
/*
p ez, if anything should've just been locked and written the equation
division and long double - fucked
say paintings are a, b, c
ax^2+bx+c
area c= (a + 2w) ^ 2 + ...
=a^2+4w^2+4aw + ...
c = a^2+b^2+...+4(a+b+...) * w + 4nw^2
0 = sumsq - c
a^2+b^2+c^2=sum of painting area
(a+2w)^2+(b+2w)^2+...= c; find w quickly
a^2+2aw+4w^2+...
c = = a^2 + 4w^2+2aw + ...
=a^2+b^2+c^2 + ... 2aw + 2bw + 2cw + ... + 4nw^2
0 = sumsq + 4nw^2 + 2w(a+b+c+d+....) - c
quadratic formula
= 4nw^2+2w(a+b+c+d)
= 4nw^2+2w(a+b+...) - c +a^2+b^2+c^2+...
*/
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

21
codeforces/886/e.in Normal file
View file

@ -0,0 +1,21 @@
10
3 50
3 2 1
1 100
6
5 500
2 2 2 2 2
2 365
3 4
2 469077255466389
10000 2023
10 635472106413848880
9181 4243 7777 1859 2017 4397 14 9390 2245 7225
7 176345687772781240
9202 9407 9229 6257 7743 5738 7966
14 865563946464579627
3654 5483 1657 7571 1639 9815 122 9468 3079 2666 5498 4540 7861 5384
19 977162053008871403
9169 9520 9209 9013 9300 9843 9933 9454 9960 9167 9964 9701 9251 9404 9462 9277 9661 9164 9161
18 886531871815571953
2609 10 5098 9591 949 8485 6385 4586 1064 5412 6564 8460 2245 6552 5089 8353 3803 3764

13
codeforces/886/e.out Normal file
View file

@ -0,0 +1,13 @@
1
2
4
5
7654321
126040443
79356352
124321725
113385729
110961227
[code]: 0
[time]: 14.693 ms

258
codeforces/886/f.cc Normal file
View file

@ -0,0 +1,258 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto &&x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto &&x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
#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 = null_type>
using hashtable = 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>>;
#endif
#ifdef PB_DS_TREE_POLICY_HPP
template <typename T>
using multitree = 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() {
// division/math is weak point, but good amortized analysis
// should be able to evaluate/come up with S(n=10^5)
// instead of typing it into python
// series/real analysis weakness
// NOTE: better workflow for testing, i can't be certain if i would've tested
// with 10^5 numbers 1..10^5 because i was on an airplane, but i tested it now
int n;
cin >> n;
ve<ll> a(n);
hashtable<int, int> f;
for (auto &e : a) {
cin >> e;
++f[e];
}
ve<int> sieve(n + 1, 0);
for (auto [k, v] : f) {
ll K = k;
while (K <= n) {
sieve[K] += v;
K += k;
}
}
// TC: O(n + n + n / 2 + n / 3 + n / 4)
// with n <= 10^5, that's O(14 n), which should be fine
prln("{}", *max_element(all(sieve)));
/*
n + n / 2 + n / 3 + n / 4
1 + 1 / 2 + 1 / 3 + 1 / 4
a, 2a, 3a, 4a
b, 2b, 3b, 4b
c, 2c, 3c, 4c
looking for number most frogs hit
most frequent common multiple
can't scan frog hop distances
sort them
a
b
makes sense to choose earliest hop in common for now
lcm(a, b), ans = 2 (NOTE: if <= 10^9)
find c: trap: lcm(a, b, c), ans = 3
or don't: lcm(a, b), lcm(c) = c
^ prob dp?
binary search on place to trap, check if can trap:
time-wise yes
if can trap a at position x? x % a = 0
no monotonic search space?
consider iterating from trap=1..n
how many frogs can i trap?
number of frogs s.t. trap % frog = 0
*/
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

17
codeforces/886/f.in Normal file

File diff suppressed because one or more lines are too long

11
codeforces/886/f.out Normal file
View file

@ -0,0 +1,11 @@
3
3
3
5
0
4
4
128
[code]: 0
[time]: 21.6208 ms

246
codeforces/886/g.cc Normal file
View file

@ -0,0 +1,246 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto &&x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto &&x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
#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 = null_type>
using hashtable = 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>>;
#endif
#ifdef PB_DS_TREE_POLICY_HPP
template <typename T>
using multitree = 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;
// NOTE: keep forgetting to initialize vector with size
// NOTE: thought could just use angles -> completely wrong
ve<pa<ll, ll>> points(n);
map<ll, ll> xs, ys;
for (int i = 0; i < n; ++i) {
cin >> points[i].ff >> points[i].ss;
++xs[points[i].ff];
++ys[points[i].ss];
}
ll ans = 0;
for (auto [_, f] : xs) {
ans += f * (f - 1) / 2;
}
for (auto [_, f] : ys) {
ans += f * (f - 1) / 2;
}
xs.clear();
ys.clear();
// NOTE: claude did tihs, to account for precision errors, no idea why this
// works
for (auto [x, y] : points) {
ll rx = x + y;
ll ry = x - y;
++xs[rx];
++ys[ry];
}
for (auto [_, f] : xs) {
ans += f * (f - 1) / 2;
}
for (auto [_, f] : ys) {
ans += f * (f - 1) / 2;
}
prln("{}", ans * 2);
// WRONG:
// for the fun of it, let's change this up - find the angle each point makes
// with 0 then should be same counting approach
// should be: count all points with same y value, n * (n - 1) / 2
// and same x
// then rotate 45 degrees, do the same- guaranteed no overcounting
// PAUSED AT 17:00
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

29
codeforces/886/g.in Normal file
View file

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

9
codeforces/886/g.out Normal file
View file

@ -0,0 +1,9 @@
6
2
6
8
0
12
[code]: 0
[time]: 14.0719 ms

96
codeforces/886/h.cc Normal file
View file

@ -0,0 +1,96 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

0
codeforces/886/h.in Normal file
View file

0
codeforces/886/h.out Normal file
View file

View file

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

8
codeforces/895/.clangd Normal file
View file

@ -0,0 +1,8 @@
CompileFlags:
Add:
- -Wall
- -Wextra
- -Wpedantic
- -Wshadow
- -DLOCAL
- -Wno-unknown-pragmas

79
codeforces/895/a.cc Normal file
View file

@ -0,0 +1,79 @@
#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> [[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T> [[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T> [[nodiscard]] static T sc(auto &&x) {
return static_cast<T>(x);
}
template <typename T> [[nodiscard]] static T sz(auto &&x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() { prln("NO"); }
inline static void YES() { prln("YES"); }
using ll = long long;
using ld = long double;
template <typename T> using ve = std::vector<T>;
template <typename T, size_t N> using ar = std::array<T, N>;
template <typename T1, typename T2> using pa = std::pair<T1, T2>;
template <typename... Ts> using tu = std::tuple<Ts...>;
template <typename... Ts> using dq = std::deque<Ts...>;
template <typename... Ts> using qu = std::queue<Ts...>;
template <typename... Ts> using pq = std::priority_queue<Ts...>;
template <typename... Ts> using st = std::stack<Ts...>;
auto lb = [](auto... args) { return std::lower_bound(args...); };
auto ub = [](auto... args) { return std::upper_bound(args...); };
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
ld a, b, c;
cin >> a >> b >> c;
prln("{}", ceill(abs((b - a) / 2) / c));
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

7
codeforces/895/a.in Normal file
View file

@ -0,0 +1,7 @@
6
3 7 2
17 4 3
17 17 1
17 21 100
1 100 1
97 4 3

9
codeforces/895/a.out Normal file
View file

@ -0,0 +1,9 @@
1
3
0
1
50
16
[code]: 0
[time]: 13.0444 ms

105
codeforces/895/b.cc Normal file
View file

@ -0,0 +1,105 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
int n;
cin >> n;
ll d, s;
ll ans = MAX<ll>();
for (int i = 0; i < n; ++i) {
cin >> d >> s;
ans = min(ans, d + (ll)ceill(s / 2.0));
}
prln("{}", ans - 1);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

24
codeforces/895/b.in Normal file
View file

@ -0,0 +1,24 @@
7
1
2 2
3
2 8
4 3
5 2
1
200 200
4
1 20
5 9
3 179
100 1
2
10 1
1 18
2
1 1
1 2
3
1 3
1 1
1 3

10
codeforces/895/b.out Normal file
View file

@ -0,0 +1,10 @@
2
5
299
9
9
1
1
[code]: 0
[time]: 13.6361 ms

111
codeforces/895/c.cc Normal file
View file

@ -0,0 +1,111 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
ll l, r;
cin >> l >> r;
for (ll x = l; x <= r; ++x) {
ll md = x;
for (ll d = 2; d <= sqrtl(x); ++d) {
if (x % d == 0) {
md = d;
break;
}
}
if (md != x) {
prln("{} {}", md, x - md);
return;
}
}
prln("-1");
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

12
codeforces/895/c.in Normal file
View file

@ -0,0 +1,12 @@
11
11 15
1 3
18 19
41 43
777 777
8000000 10000000
2000 2023
1791791 1791791
1 4
2 3
9840769 9840769

14
codeforces/895/c.out Normal file
View file

@ -0,0 +1,14 @@
2 10
-1
2 16
2 40
3 774
2 7999998
2 1998
-1
2 2
-1
3137 9837632
[code]: 0
[time]: 13.5865 ms

View file

@ -0,0 +1,6 @@
-Wall
-Wextra
-Wpedantic
-Wshadow
-DLOCAL
-std=c++23

110
codeforces/895/d.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 T>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
ll lcm(ll x, ll y) {
// TODO: why?
return x * y / gcd(x, y);
}
void solve() {
ld n;
ll x, y;
cin >> n >> x >> y;
ll overlaps = floorl(n / (lcm(x, y)));
ll x_o = floorl(n / x) - overlaps;
ll y_o = floorl(n / y) - overlaps;
prln("{}",
n * (n + 1) / 2 - (n - x_o) * (n - x_o + 1) / 2 - (y_o + 1) * (y_o) / 2);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

9
codeforces/895/d.in Normal file
View file

@ -0,0 +1,9 @@
8
7 2 3
12 6 3
9 1 9
2 2 2
100 20 50
24 4 6
1000000000 5575 25450
4 4 1

11
codeforces/895/d.out Normal file
View file

@ -0,0 +1,11 @@
12
-3
44
0
393
87
179179179436104
-6
[code]: 0
[time]: 15.0597 ms

127
codeforces/895/e.cc Normal file
View file

@ -0,0 +1,127 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
int n;
cin >> n;
ve<ll> a(n), prefix(n);
for (auto& e : a)
cin >> e;
string s;
cin >> s;
int zeroes = 0;
for (int i = 0; i < n; ++i) {
prefix[i] = a[i] ^ (i ? prefix[i - 1] : 0);
if (s[i] == '0')
zeroes ^= a[i];
}
int q;
cin >> q;
int cmd, l, r, g;
while (q--) {
cin >> cmd;
if (cmd == 1) {
cin >> l >> r;
--l;
--r;
zeroes ^= prefix[r] ^ (l ? prefix[l - 1] : 0);
} else {
cin >> g;
if (g == 0)
pr("{} ", zeroes);
else
pr("{} ", prefix.back() ^ zeroes);
}
}
prln();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

40
codeforces/895/e.in Normal file
View file

@ -0,0 +1,40 @@
5
5
1 2 3 4 5
01000
7
2 0
2 1
1 2 4
2 0
2 1
1 1 3
2 1
6
12 12 14 14 5 5
001001
3
2 1
1 2 4
2 1
4
7 7 7 777
1111
3
2 0
1 2 3
2 0
2
1000000000 996179179
11
1
2 1
5
1 42 20 47 7
00011
5
1 3 4
1 1 1
1 3 4
1 2 4
2 0

8
codeforces/895/e.out Normal file
View file

@ -0,0 +1,8 @@
3 2 6 7 7
11 7
0 0
16430827
47
[code]: 0
[time]: 13.0174 ms

View file

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

8
codeforces/900/.clangd Normal file
View file

@ -0,0 +1,8 @@
CompileFlags:
Add:
- -Wall
- -Wextra
- -Wpedantic
- -Wshadow
- -DLOCAL
- -Wno-unknown-pragmas

105
codeforces/900/a.cc Normal file
View file

@ -0,0 +1,105 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
int n, k;
cin >> n >> k;
int x;
bool good = false;
while (n--) {
cin >> x;
if (x == k) good = true;
}
if (good) YES(); else NO();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

15
codeforces/900/a.in Normal file
View file

@ -0,0 +1,15 @@
7
5 4
1 4 3 4 1
4 1
2 3 4 4
5 6
43 5 60 4 2
2 5
1 5
4 1
5 3 3 1
1 3
3
5 3
3 4 1 5 5

0
codeforces/900/a.out Normal file
View file

105
codeforces/900/b.cc Normal file
View file

@ -0,0 +1,105 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
int n;
cin >> n;
ll x = 1;
for (int i = 0; i < n; ++i) {
pr("{} ", x);
x += 2;
}
prln();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

2
codeforces/900/b.in Normal file
View file

@ -0,0 +1,2 @@
1
200000

4
codeforces/900/b.out Normal file

File diff suppressed because one or more lines are too long

104
codeforces/900/c.cc Normal file
View file

@ -0,0 +1,104 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
void solve() {
ll n, k, x;
cin >> n >> k >> x;
ll small = k * (k + 1) / 2;
ll large = n * (n + 1) / 2 - (n - k + 1) * (n - k) / 2;
if (small <= x && x <= large) {
YES();
} else
NO();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

14
codeforces/900/c.in Normal file
View file

@ -0,0 +1,14 @@
12
5 3 10
5 3 3
10 10 55
6 5 20
2 1 26
187856 87856 2609202300
200000 190000 19000000000
28 5 2004
2 2 2006
9 6 40
47202 32455 613407217
185977 145541 15770805980

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

@ -0,0 +1,15 @@
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
[code]: 0
[time]: 14.3909 ms

View file

@ -0,0 +1,6 @@
-Wall
-Wextra
-Wpedantic
-Wshadow
-DLOCAL
-std=c++23

157
codeforces/900/d.cc Normal file
View file

@ -0,0 +1,157 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
string reverseIntervals(string s, vector<pair<int, int>>& intervals) {
int n = s.length();
vector<int> flip(n + 1, 0);
for (auto& interval : intervals) {
int start = interval.ff, end = interval.ss;
if (start >= 0 && end < n && start <= end) {
flip[start]++;
flip[end + 1]--;
}
}
int current = 0;
for (int i = 0; i < n; ++i) {
current += flip[i];
if (current % 2 == 1) {
int j = n - 1 - i;
if (i < j) {
swap(s[i], s[j]);
}
}
}
return s;
}
void solve() {
int k, n;
cin >> n >> k;
string s;
cin >> s;
ve<int> L(k), R(k);
for (auto& e : L)
cin >> e;
for (auto& e : R)
cin >> e;
int q;
cin >> q;
int x;
ve<pa<int, int>> intervals;
while (q--) {
cin >> x;
int l = 0, r = k - 1;
while (l <= r) {
int m = l + (r - l) / 2;
if (L[m] <= x) {
l = m + 1;
} else {
r = m - 1;
}
}
int i = r;
int left = min(x, R[i] + L[i] - x), right = max(x, R[i] + L[i] - x);
prln("{} {}", left - 1, right - 1);
intervals.eb(left - 1, right - 1);
}
string ans = reverseIntervals(s, intervals);
prln("{}", ans);
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

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

@ -0,0 +1,31 @@
5
4 2
abcd
1 3
2 4
1
1
5 3
abcde
1 2 3
1 2 5
3
1 2 3
3 1
gaf
1
3
2
2 2
10 1
aghcdegdij
1
10
5
1 2 3 4 2
1 1
a
1
1
1
1

20
codeforces/900/d.out Normal file
View file

@ -0,0 +1,20 @@
0 1
dcba
0 0
1 1
2 4
edcba
1 1
1 1
gaf
0 9
1 8
2 7
3 6
1 8
jihgedcdga
0 0
a
[code]: 0
[time]: 14.6108 ms

257
codeforces/900/e.cc Normal file
View file

@ -0,0 +1,257 @@
#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>
[[nodiscard]] static T MIN() {
return std::numeric_limits<T>::min();
}
template <typename T>
[[nodiscard]] static T MAX() {
return std::numeric_limits<T>::max();
}
template <typename T>
[[nodiscard]] static T sc(auto&& x) {
return static_cast<T>(x);
}
template <typename T>
[[nodiscard]] static T sz(auto&& x) {
return static_cast<T>(x.size());
}
#define prln(...) std::println(__VA_ARGS__)
#define pr(...) std::print(__VA_ARGS__)
#ifdef LOCAL
#define dbgln(...) std::println(__VA_ARGS__)
#define dbg(...) std::print(__VA_ARGS__)
#endif
inline static void NO() {
prln("NO");
}
inline static void YES() {
prln("YES");
}
using ll = long long;
using ld = long double;
template <typename T>
using ve = std::vector<T>;
template <typename T, size_t N>
using ar = std::array<T, N>;
template <typename T1, typename T2>
using pa = std::pair<T1, T2>;
template <typename... Ts>
using tu = std::tuple<Ts...>;
template <typename... Ts>
using dq = std::deque<Ts...>;
template <typename... Ts>
using qu = std::queue<Ts...>;
template <typename... Ts>
using pq = std::priority_queue<Ts...>;
template <typename... Ts>
using st = std::stack<Ts...>;
auto lb = [](auto... args) {
return std::lower_bound(args...);
};
auto ub = [](auto... args) {
return std::upper_bound(args...);
};
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// }}}
template <typename T>
struct segment_tree {
public:
explicit segment_tree(std::vector<T> const& ts) : n(ts.size()) {
tree.resize(4 * n);
build(1, 0, n - 1, ts);
}
[[nodiscard]] T const query(int const l, int const r) const {
if (!(0 <= l && l <= r && r < static_cast<int>(n))) {
throw std::out_of_range(
"cannot query segment tree of size " + std::to_string(n) +
" at range [" + std::to_string(l) + ", " + std::to_string(r) + "]");
}
return query(1, 0, n - 1, l, r);
}
void update(int i, T const& t) {
if (!(0 <= i && i < static_cast<int>(n))) {
throw std::out_of_range("cannot update segment tree of size " +
std::to_string(n) + " at index " +
std::to_string(i));
}
update(1, 0, n - 1, i, t);
}
[[nodiscard]] size_t lower_bound(T const& t) const noexcept {
return lower_bound(1, 0, n - 1, t);
}
[[nodiscard]] size_t upper_bound(T const& t) const noexcept {
return upper_bound(1, 0, n - 1, t);
}
private:
inline T const sentinel() const noexcept {
return -1LL;
}
inline T const merge(T const& x, T const& y) const noexcept {
return x & y;
}
void build(size_t const node, size_t const l, size_t const r,
std::vector<T> const& ts) noexcept {
if (l == r) {
tree[node] = ts[l];
} else {
int m = l + (r - l) / 2;
build(2 * node, l, m, ts);
build(2 * node + 1, m + 1, r, ts);
tree[node] = merge(tree[2 * node], tree[2 * node + 1]);
}
}
[[nodiscard]] T query(size_t const node, size_t const lower,
size_t const upper, size_t const l,
size_t const r) const noexcept {
if (upper < l || r < lower) {
return sentinel();
}
if (l <= lower && upper <= r) {
return tree[node];
}
size_t m = lower + (upper - lower) / 2;
return merge(query(2 * node, lower, m, l, r),
query(2 * node + 1, m + 1, upper, l, r));
}
void update(size_t const node, size_t const l, size_t const r, size_t const i,
T const& t) noexcept {
if (l == r) {
tree[node] = t;
} else {
size_t m = l + (r - l) / 2;
if (i <= m) {
update(2 * node, l, m, i, t);
} else {
update(2 * node + 1, m + 1, r, i, t);
}
tree[node] = merge(tree[2 * node], tree[2 * node + 1]);
}
}
[[nodiscard]] size_t lower_bound(size_t const node, size_t const l,
size_t const r, T const& t) const noexcept {
if (l == r) {
return tree[node] >= t ? l : n;
}
size_t m = l + (r - l) / 2;
if (tree[2 * node] >= t) {
size_t res = lower_bound(2 * node, l, m, t);
if (res < n)
return res;
}
return lower_bound(2 * node + 1, m + 1, r, t);
}
[[nodiscard]] size_t upper_bound(size_t const node, size_t const l,
size_t const r, T const& t) const noexcept {
if (l == r) {
return tree[node] > t ? l : n;
}
size_t m = l + (r - l) / 2;
if (tree[2 * node] > t) {
size_t res = upper_bound(2 * node, l, m, t);
if (res < n)
return res;
}
return upper_bound(2 * node + 1, m + 1, r, t);
}
size_t n;
std::vector<T> tree;
};
void solve() {
int n;
cin >> n;
ve<ll> a(n);
for (auto& e : a)
cin >> e;
segment_tree<ll> st(a);
int q;
cin >> q;
int L;
ll k;
while (q--) {
cin >> L >> k;
--L;
int l = L;
int r = n - 1;
while (l <= r) {
int m = l + (r - l) / 2;
if (st.query(L, m) >= k) {
l = m + 1;
} else {
r = m - 1;
}
}
// NOTE: messed up invalid queries, was confused
// minor details of algorithms still cofnuse
if (r < L)
pr("-1 ");
else
pr("{} ", r + 1);
// NOTE: would like to be able to use builtin lower bound but knowledge not
// good enough
}
prln();
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
// }}}

21
codeforces/900/e.in Normal file
View file

@ -0,0 +1,21 @@
3
5
15 14 17 42 34
3
1 7
2 15
4 5
5
7 5 3 1 7
4
1 7
5 7
2 3
2 2
7
19 20 15 12 21 7 11
4
1 15
4 4
7 12
5 7

6
codeforces/900/e.out Normal file
View file

@ -0,0 +1,6 @@
2 -1 5
1 5 2 2
2 6 -1 5
[code]: 0
[time]: 13.607 ms