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/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