895
This commit is contained in:
parent
94383fbaf7
commit
26f66e43d8
97 changed files with 5337 additions and 42 deletions
9
codeforces/888/.clang-format
Normal file
9
codeforces/888/.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/888/.clangd
Normal file
8
codeforces/888/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
110
codeforces/888/a.cc
Normal file
110
codeforces/888/a.cc
Normal 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()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n, m, k, H;
|
||||
cin >> n >> m >> k >> H;
|
||||
|
||||
int ans = 0;
|
||||
int h;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> h;
|
||||
|
||||
auto diff = abs(h - H);
|
||||
if (diff % k == 0 && diff / k < m && diff / k > 0) {
|
||||
++ans;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
15
codeforces/888/a.in
Normal file
15
codeforces/888/a.in
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
7
|
||||
5 3 3 11
|
||||
5 4 14 18 2
|
||||
2 9 5 6
|
||||
11 9
|
||||
10 50 3 11
|
||||
43 44 74 98 62 60 99 4 11 73
|
||||
4 8 8 49
|
||||
68 58 82 73
|
||||
7 1 4 66
|
||||
18 66 39 83 48 99 79
|
||||
9 1 1 13
|
||||
26 23 84 6 60 87 40 41 25
|
||||
6 13 3 28
|
||||
30 70 85 13 1 55
|
||||
10
codeforces/888/a.out
Normal file
10
codeforces/888/a.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
2
|
||||
1
|
||||
4
|
||||
1
|
||||
0
|
||||
0
|
||||
3
|
||||
|
||||
[code]: 0
|
||||
[time]: 15.1486 ms
|
||||
137
codeforces/888/b.cc
Normal file
137
codeforces/888/b.cc
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
#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<int> odds, evens, odd_is, even_is;
|
||||
|
||||
int x;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> x;
|
||||
if (x & 1) {
|
||||
odds.eb(x);
|
||||
odd_is.eb(i);
|
||||
} else {
|
||||
evens.eb(x);
|
||||
even_is.eb(i);
|
||||
}
|
||||
}
|
||||
|
||||
sort(all(evens));
|
||||
sort(all(even_is));
|
||||
sort(all(odds));
|
||||
sort(all(odd_is));
|
||||
|
||||
int e = 0, o = 0;
|
||||
int last = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (e < sz<int>(even_is) && even_is[e] == i) {
|
||||
if (i && evens[e] < last) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
last = evens[e];
|
||||
++e;
|
||||
} else {
|
||||
if (i && odds[o] < last) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
last = odds[o];
|
||||
++o;
|
||||
}
|
||||
}
|
||||
|
||||
YES();
|
||||
}
|
||||
|
||||
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/888/b.in
Normal file
13
codeforces/888/b.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
5
|
||||
7 10 1 3 2
|
||||
4
|
||||
11 9 3 5
|
||||
5
|
||||
11 3 15 3 2
|
||||
6
|
||||
10 7 8 1 2 3
|
||||
1
|
||||
10
|
||||
5
|
||||
6 6 4 1 6
|
||||
11
codeforces/888/b.out
Normal file
11
codeforces/888/b.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[code]: 0
|
||||
|
||||
[time]: 5.26595 ms[time]: 11.1866 ms
|
||||
146
codeforces/888/c.cc
Normal file
146
codeforces/888/c.cc
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
#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<int> colors(n);
|
||||
for (auto& e : colors) {
|
||||
cin >> e;
|
||||
}
|
||||
|
||||
// have to start on tile 1, greedily take first k
|
||||
// then, greedily take (backwards) from n - 1 until when you stopped
|
||||
// note divisibility
|
||||
|
||||
int seen = 0;
|
||||
int i;
|
||||
for (i = 0; i < n && seen < k; ++i) {
|
||||
if (colors[i] == colors[0])
|
||||
++seen;
|
||||
}
|
||||
|
||||
if (colors[0] == colors[n - 1]) {
|
||||
int x = 0;
|
||||
for (int j = 0; j < n; ++j)
|
||||
if (colors[j] == colors[0])
|
||||
++x;
|
||||
if (x >= k) {
|
||||
YES();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// dbgln("found first {} elems {}, ending at {}", seen, colors[0], i);
|
||||
|
||||
if (i == n) {
|
||||
if (seen % k == 0) {
|
||||
YES();
|
||||
} else {
|
||||
NO();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
seen = 0;
|
||||
for (int j = n - 1; j >= i && seen < k; --j) {
|
||||
if (colors[j] == colors[n - 1])
|
||||
++seen;
|
||||
}
|
||||
|
||||
if (seen % k == 0) {
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
21
codeforces/888/c.in
Normal file
21
codeforces/888/c.in
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
10
|
||||
4 2
|
||||
1 1 1 1
|
||||
14 3
|
||||
1 2 1 1 7 5 3 3 1 3 4 4 2 4
|
||||
3 3
|
||||
3 1 3
|
||||
10 4
|
||||
1 2 1 2 1 2 1 2 1 2
|
||||
6 2
|
||||
1 3 4 1 6 6
|
||||
2 2
|
||||
1 1
|
||||
4 2
|
||||
2 1 1 1
|
||||
2 1
|
||||
1 2
|
||||
3 2
|
||||
2 2 2
|
||||
4 1
|
||||
1 1 2 2
|
||||
13
codeforces/888/c.out
Normal file
13
codeforces/888/c.out
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 15.0125 ms
|
||||
6
codeforces/888/compile_flags.txt
Normal file
6
codeforces/888/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
112
codeforces/888/d.cc
Normal file
112
codeforces/888/d.cc
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename 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> perm(n - 1);
|
||||
int j = -1;
|
||||
unoredered_set<int> seen;
|
||||
set<int> seen;
|
||||
for (int i = 0; i < n - 1; ++i) {
|
||||
cin >> perm[i];
|
||||
if (i) {
|
||||
int diff = abs(perm[i] - perm[i - 1]);
|
||||
if (diff >= n) {
|
||||
j = i;
|
||||
} else {
|
||||
seen.insert(diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
25
codeforces/888/d.in
Normal file
25
codeforces/888/d.in
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
12
|
||||
5
|
||||
6 8 12 15
|
||||
5
|
||||
1 6 8 15
|
||||
4
|
||||
1 2 100
|
||||
4
|
||||
1 3 6
|
||||
2
|
||||
2
|
||||
3
|
||||
1 2
|
||||
4
|
||||
3 7 10
|
||||
5
|
||||
5 44 46 50
|
||||
4
|
||||
1 9 10
|
||||
5
|
||||
13 21 36 42
|
||||
5
|
||||
1 2 3 1000000000000000000
|
||||
9
|
||||
9 11 12 20 25 28 30 33
|
||||
15
codeforces/888/d.out
Normal file
15
codeforces/888/d.out
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 6.00839 ms
|
||||
137
codeforces/888/e.cc
Normal file
137
codeforces/888/e.cc
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
#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()
|
||||
// }}}
|
||||
|
||||
bitset<2 * 100000 + 1> seen;
|
||||
|
||||
void solve() {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
seen.reset();
|
||||
ve<ll> c(n + 1);
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
cin >> c[i];
|
||||
}
|
||||
int p;
|
||||
for (int i = 1; i <= k; ++i) {
|
||||
cin >> p;
|
||||
c[p] = 0;
|
||||
seen[p] = true;
|
||||
}
|
||||
int m;
|
||||
ve<ve<ll>> recipes(n + 1);
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
cin >> m;
|
||||
recipes[i].resize(m);
|
||||
for (int j = 0; j < m; ++j) {
|
||||
cin >> recipes[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
int x = 3;
|
||||
|
||||
auto dfs = [&](auto&& self, int u) {
|
||||
if (seen[u] || recipes[u].empty())
|
||||
return c[u];
|
||||
seen[u] = true;
|
||||
ll total = 0;
|
||||
for (auto& v : recipes[u])
|
||||
total += self(self, v);
|
||||
c[u] = min(c[u], total);
|
||||
return c[u];
|
||||
};
|
||||
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
pr("{} ", dfs(dfs, 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;
|
||||
}
|
||||
// }}}
|
||||
30
codeforces/888/e.in
Normal file
30
codeforces/888/e.in
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
4
|
||||
5 1
|
||||
30 8 3 5 10
|
||||
3
|
||||
3 2 4 5
|
||||
0
|
||||
0
|
||||
2 3 5
|
||||
0
|
||||
3 2
|
||||
5 143 3
|
||||
1 3
|
||||
1 2
|
||||
0
|
||||
2 1 2
|
||||
5 1
|
||||
5 4 1 3 4
|
||||
2
|
||||
2 4 5
|
||||
3 3 5 4
|
||||
2 1 4
|
||||
1 5
|
||||
0
|
||||
4 2
|
||||
1 1 5 4
|
||||
2 4
|
||||
3 2 4 3
|
||||
0
|
||||
2 2 4
|
||||
1 2
|
||||
7
codeforces/888/e.out
Normal file
7
codeforces/888/e.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
23 8 0 5 10
|
||||
0 143 0
|
||||
5 0 1 3 4
|
||||
0 0 0 0
|
||||
|
||||
[code]: 0
|
||||
[time]: 14.1129 ms
|
||||
174
codeforces/888/g.cc
Normal file
174
codeforces/888/g.cc
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename 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 union_find {
|
||||
public:
|
||||
explicit union_find(size_t capacity)
|
||||
: par(capacity + 1, 0), rank(capacity + 1, 0) {
|
||||
std::iota(par.begin(), par.end(), 0);
|
||||
};
|
||||
|
||||
void join(T u, T v) noexcept {
|
||||
u = find(u), v = find(v);
|
||||
|
||||
if (u == v)
|
||||
return;
|
||||
|
||||
if (rank[u] < rank[v])
|
||||
std::swap(u, v);
|
||||
|
||||
if (rank[u] == rank[v])
|
||||
++rank[u];
|
||||
|
||||
par[v] = u;
|
||||
}
|
||||
|
||||
[[nodiscard]] T find(T const& u) noexcept {
|
||||
if (u != par[u])
|
||||
par[u] = find(par[u]);
|
||||
return par[u];
|
||||
}
|
||||
|
||||
std::vector<T> par;
|
||||
std::vector<int> rank;
|
||||
};
|
||||
|
||||
void solve() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
ve<ll> heights(n + 1);
|
||||
for (int i = 1; i <= n; ++i)
|
||||
cin >> heights[i];
|
||||
|
||||
ve<ar<ll, 3>> roads(m);
|
||||
for (int i = 0; i < m; ++i) {
|
||||
int u, v;
|
||||
cin >> u >> v;
|
||||
if (heights[u] > heights[v]) {
|
||||
roads.pb({heights[u] - heights[v], u, v});
|
||||
} else {
|
||||
roads.pb({heights[v] - heights[v], v, u});
|
||||
}
|
||||
}
|
||||
|
||||
sort(all(roads));
|
||||
union_find<int> uf(n);
|
||||
|
||||
int q;
|
||||
cin >> q;
|
||||
ve<ar<ll, 5>> queries(q);
|
||||
for (int i = 0; i < q; ++i) {
|
||||
ll a, b, e;
|
||||
cin >> a >> b >> e;
|
||||
queries[i] = {heights[a] + e, a, b, e, i};
|
||||
}
|
||||
sort(all(queries));
|
||||
|
||||
ve<bool> ans(n, false);
|
||||
|
||||
for (auto& [hab, a, b, e, i] : queries) {
|
||||
while (i < m && roads[i][0] <= hab && roads[i][1] <= hab) {
|
||||
uf.join(a, roads[0][1]);
|
||||
uf.join(a, roads[0][2]);
|
||||
++i;
|
||||
}
|
||||
|
||||
ans[i] = uf.find(a) == uf.find(b);
|
||||
}
|
||||
|
||||
for (auto e : ans) {
|
||||
e ? YES() : NO();
|
||||
}
|
||||
}
|
||||
|
||||
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/888/g.in
Normal file
29
codeforces/888/g.in
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
2
|
||||
7 7
|
||||
1 5 3 4 2 4 1
|
||||
1 4
|
||||
4 3
|
||||
3 6
|
||||
3 2
|
||||
2 5
|
||||
5 6
|
||||
5 7
|
||||
5
|
||||
1 1 3
|
||||
6 2 0
|
||||
4 7 0
|
||||
1 7 4
|
||||
1 7 2
|
||||
6 5
|
||||
4 7 6 2 5 1
|
||||
1 3
|
||||
5 3
|
||||
1 5
|
||||
2 4
|
||||
6 2
|
||||
5
|
||||
1 5 1
|
||||
1 3 1
|
||||
1 2 1000
|
||||
6 2 6
|
||||
6 2 5
|
||||
16
codeforces/888/g.out
Normal file
16
codeforces/888/g.out
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 13.5758 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue