update
This commit is contained in:
parent
59d8a872b6
commit
2a8ecba5b9
67 changed files with 2648 additions and 15 deletions
|
|
@ -37,3 +37,7 @@ CompileFlags:
|
|||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
|
|
|
|||
102
codeforces/1032/e.cc
Normal file
102
codeforces/1032/e.cc
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#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;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
random_device rd;
|
||||
mt19937 engine(rd());
|
||||
|
||||
void solve() {
|
||||
u64 l, r;
|
||||
cin >> l >> r;
|
||||
|
||||
uniform_int_distribution<> dist(l, r);
|
||||
|
||||
u64 ans = 20;
|
||||
|
||||
for (u32 i = 0; i < 200; ++i) {
|
||||
u64 candidate = dist(engine);
|
||||
u64 L = l, R = r;
|
||||
u64 cur = 0;
|
||||
|
||||
for (u64 X = candidate; X > 0; R /= 10, X /= 10) {
|
||||
cur += X % 10 == R % 10;
|
||||
}
|
||||
for (u64 X = candidate; L > 0; L /= 10, X /= 10) {
|
||||
cur += X % 10 == L % 10;
|
||||
}
|
||||
|
||||
ans = min(ans, cur);
|
||||
}
|
||||
|
||||
println("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
u32 tc = 1;
|
||||
cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
109
codeforces/1032/f.cc
Normal file
109
codeforces/1032/f.cc
Normal 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;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
u64 count_subarrays(i64 s, i64 x, vec<i64>& a) {
|
||||
u64 ans = 0;
|
||||
map<i64, vec<i32>> pref;
|
||||
pref[0].push_back(-1);
|
||||
i64 acc = 0;
|
||||
i32 last_bad = -1;
|
||||
|
||||
for (u32 r = 0; r < a.size(); ++r) {
|
||||
acc += a[r];
|
||||
if (a[r] > x)
|
||||
last_bad = r;
|
||||
|
||||
i64 target = acc - s;
|
||||
auto& indices = pref[target];
|
||||
auto it = lower_bound(indices.begin(), indices.end(), last_bad);
|
||||
ans += (u64)distance(it, indices.end());
|
||||
|
||||
pref[acc].push_back(r);
|
||||
}
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
i64 s, x;
|
||||
cin >> n >> s >> x;
|
||||
vec<i64> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
auto X = count_subarrays(s, x, a);
|
||||
auto Y = count_subarrays(s, x - 1, a);
|
||||
println("{}", X - Y);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
u32 tc = 1;
|
||||
cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
116
codeforces/1032/g.cc
Normal file
116
codeforces/1032/g.cc
Normal 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;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
/*
|
||||
|
||||
f(x) -> max # 0/1s in x
|
||||
|
||||
count f(s[l: r]) for all l <= r
|
||||
|
||||
formulate it
|
||||
|
||||
|
||||
f(s[l:r])
|
||||
|
||||
f(s[0:0]) + f(s[0:1]) + f(s[0:2]) + f(s[0:3]) + f(s[0:4]) + ...
|
||||
f(s[1:1]) + f(s[1:2]) + f(s[1:3]) + f(s[1:4]) + ...
|
||||
|
||||
one idea: sum f(s[l:r]) = sum min(prefix[0][l][r], prefix[1][l][r]) +
|
||||
|prefix[0][l][r] - prefix[1][l[r]]| = sum + sum
|
||||
|
||||
first term:
|
||||
= (i + 1) * (n - i), take min
|
||||
|
||||
min doesn't work, since varies
|
||||
|
||||
must leverage: max(x, y) = (x + y + |x-y|)/2 = sum x + y
|
||||
for all i:
|
||||
cnts[s[i] == 0] += (i + 1) * (n - i)
|
||||
|
||||
|
||||
div. by 2 after
|
||||
|
||||
second term: |x-y| in an aggregate way
|
||||
|
||||
|
||||
|
||||
ret (first + second) / 2
|
||||
*/
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
u32 tc = 1;
|
||||
cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
1 2
|
||||
2 1
|
||||
5 0
|
||||
15 3
|
||||
18 2
|
||||
199 3
|
||||
899 5
|
||||
1990 4
|
||||
6309 7
|
||||
12445 6
|
||||
19987 5
|
||||
746824 7
|
||||
900990999 14
|
||||
999999999 18
|
||||
2
|
||||
1
|
||||
0
|
||||
3
|
||||
2
|
||||
2
|
||||
1
|
||||
3
|
||||
3
|
||||
4
|
||||
3
|
||||
5
|
||||
12
|
||||
18
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.56085 ms
|
||||
[time]: 4.14038 ms
|
||||
[debug]: false
|
||||
19
codeforces/1032/io/f.in
Normal file
19
codeforces/1032/io/f.in
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
9
|
||||
1 0 0
|
||||
0
|
||||
1 -2 -1
|
||||
-2
|
||||
3 -1 -1
|
||||
-1 1 -1
|
||||
6 -3 -2
|
||||
-1 -1 -1 -2 -1 -1
|
||||
8 3 2
|
||||
2 2 -1 -2 3 -1 2 2
|
||||
9 6 3
|
||||
1 2 3 1 2 3 1 2 3
|
||||
13 7 3
|
||||
0 -1 3 3 3 -2 1 2 2 3 -1 0 3
|
||||
2 -2 -1
|
||||
-2 -1
|
||||
2 -2 -1
|
||||
-1 -2
|
||||
13
codeforces/1032/io/f.out
Normal file
13
codeforces/1032/io/f.out
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
1
|
||||
0
|
||||
2
|
||||
0
|
||||
2
|
||||
7
|
||||
8
|
||||
0
|
||||
0
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.81596 ms
|
||||
[debug]: false
|
||||
13
codeforces/1032/io/g.in
Normal file
13
codeforces/1032/io/g.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
1
|
||||
0
|
||||
2
|
||||
01
|
||||
4
|
||||
0110
|
||||
6
|
||||
110001
|
||||
8
|
||||
10011100
|
||||
11
|
||||
01011011100
|
||||
4
codeforces/1032/io/g.out
Normal file
4
codeforces/1032/io/g.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
[code]: 0
|
||||
[time]: 2.58684 ms
|
||||
[debug]: false
|
||||
8
codeforces/1032/proof.qmd
Normal file
8
codeforces/1032/proof.qmd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# hello
|
||||
|
||||
|
||||
l, r <= 10^9
|
||||
|
||||
so ~ 10^9 candidates
|
||||
|
||||
minimize the digit xor
|
||||
Loading…
Add table
Add a link
Reference in a new issue