feat(cf/895): nonlazy prop soln
This commit is contained in:
parent
6c16185126
commit
94383fbaf7
99 changed files with 4536 additions and 0 deletions
9
codeforces/1013/.clang-format
Normal file
9
codeforces/1013/.clang-format
Normal 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
8
codeforces/1013/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
116
codeforces/1013/a.cc
Normal file
116
codeforces/1013/a.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;
|
||||
|
||||
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
9
codeforces/1013/a.in
Normal 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
7
codeforces/1013/a.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
9
|
||||
0
|
||||
8
|
||||
15
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.8527 ms
|
||||
47
codeforces/1013/a.py
Normal file
47
codeforces/1013/a.py
Normal 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
122
codeforces/1013/b.cc
Normal 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
11
codeforces/1013/b.in
Normal 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
8
codeforces/1013/b.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
4
|
||||
0
|
||||
4
|
||||
2
|
||||
1
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.56087 ms
|
||||
109
codeforces/1013/c.cc
Normal file
109
codeforces/1013/c.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;
|
||||
|
||||
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
4
codeforces/1013/c.in
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
3
|
||||
4
|
||||
5
|
||||
3
|
||||
6
codeforces/1013/c.out
Normal file
6
codeforces/1013/c.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-1
|
||||
1 3 5 2 4
|
||||
1 3 2
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.7263 ms
|
||||
6
codeforces/1013/compile_flags.txt
Normal file
6
codeforces/1013/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
124
codeforces/1013/d.cc
Normal file
124
codeforces/1013/d.cc
Normal 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
6
codeforces/1013/d.in
Normal 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
8
codeforces/1013/d.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
2
|
||||
1
|
||||
1
|
||||
4
|
||||
2
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.7797 ms
|
||||
124
codeforces/1013/e.cc
Normal file
124
codeforces/1013/e.cc
Normal 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
5
codeforces/1013/e.in
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
5
|
||||
10
|
||||
34
|
||||
10007
|
||||
7
codeforces/1013/e.out
Normal file
7
codeforces/1013/e.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
4
|
||||
11
|
||||
49
|
||||
24317
|
||||
|
||||
[code]: 0
|
||||
[time]: 312.926 ms
|
||||
181
codeforces/1013/f.cc
Normal file
181
codeforces/1013/f.cc
Normal 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
13
codeforces/1013/f.in
Normal 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
6
codeforces/1013/f.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
2
|
||||
30
|
||||
0
|
||||
|
||||
[code]: 0
|
||||
[time]: 6.79278 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue