fea: more contests
This commit is contained in:
parent
00d23dc313
commit
c65a12a652
103 changed files with 3871 additions and 143 deletions
9
codeforces/827/.clang-format
Normal file
9
codeforces/827/.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
|
||||
45
codeforces/827/.clangd
Normal file
45
codeforces/827/.clangd
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
-O2
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-Wformat=2
|
||||
-Wfloat-equal
|
||||
-Wlogical-op
|
||||
-Wshift-overflow=2
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-qual
|
||||
-Wuseless-cast
|
||||
-Wno-sign-promotion
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wconversion
|
||||
-Wsign-conversion
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
-Wlogical-op
|
||||
-Wnull-dereference
|
||||
-Wformat=2
|
||||
-Wformat-overflow
|
||||
-Wformat-truncation
|
||||
-Wdouble-promotion
|
||||
-Wundef
|
||||
-DLOCAL
|
||||
-Wno-unknown-pragmas
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
-std=c++23
|
||||
85
codeforces/827/a.cc
Normal file
85
codeforces/827/a.cc
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#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 a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
vector<u32> X{a, b, c};
|
||||
sort(all(X));
|
||||
if (X[0] + X[1] == X[2]) {
|
||||
YES();
|
||||
} else {
|
||||
NO();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
90
codeforces/827/b.cc
Normal file
90
codeforces/827/b.cc
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#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;
|
||||
vector<u32> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
sort(all(a));
|
||||
|
||||
for (u32 i = 0; i < n - 1; ++i) {
|
||||
if (!(a[i] < a[i + 1])) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
}
|
||||
YES();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
100
codeforces/827/c.cc
Normal file
100
codeforces/827/c.cc
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#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() {
|
||||
vector<string> grid(8);
|
||||
for (auto& e : grid)
|
||||
cin >> e;
|
||||
|
||||
for (u32 r = 0; r < 8; ++r) {
|
||||
bool good = true;
|
||||
for (u32 c = 0; c < 8; ++c) {
|
||||
good &= grid[r][c] == grid[r][0];
|
||||
}
|
||||
if (good && grid[r][0] == 'R') {
|
||||
cout << grid[r][0] << '\n';
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (u32 c = 0; c < 8; ++c) {
|
||||
bool good = true;
|
||||
for (u32 r = 0; r < 8; ++r) {
|
||||
good &= grid[r][c] == grid[0][c];
|
||||
}
|
||||
if (good && grid[0][c] == 'B') {
|
||||
cout << grid[0][c] << '\n';
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
30
codeforces/827/compile_flags.txt
Normal file
30
codeforces/827/compile_flags.txt
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
-O2
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-Wformat=2
|
||||
-Wfloat-equal
|
||||
-Wlogical-op
|
||||
-Wshift-overflow=2
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-qual
|
||||
-Wuseless-cast
|
||||
-Wno-sign-promotion
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wconversion
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
-Wlogical-op
|
||||
-Wnull-dereference
|
||||
-Wformat=2
|
||||
-Wformat-overflow
|
||||
-Wformat-truncation
|
||||
-Wdouble-promotion
|
||||
-Wundef
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
123
codeforces/827/d.cc
Normal file
123
codeforces/827/d.cc
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
#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() {
|
||||
/*
|
||||
a[i] has factors S, |S| < = log2(MAX_A[i] = 1000)
|
||||
|
||||
want to find rightmost j > i s.t. no common factors
|
||||
|
||||
factor -> [a[i] divisible by]
|
||||
|
||||
iter thru factors of a[i]
|
||||
|
||||
if i have log2(a[i]) factors;
|
||||
there are 10^6 factors total
|
||||
there are 10 factors here
|
||||
|
||||
so, factor each a[i], and manually compute
|
||||
*/
|
||||
u32 n;
|
||||
cin >> n;
|
||||
vector<u32> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
vector<bitset<1001>> coprime(1001);
|
||||
for (u32 i = 1; i <= 1000; ++i) {
|
||||
for (u32 j = 1; j <= 1000; ++j) {
|
||||
coprime[i][j] = gcd(i, j) == 1;
|
||||
}
|
||||
}
|
||||
|
||||
vector<u32> right(1001, -1);
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
right[a[i]] = i;
|
||||
}
|
||||
|
||||
u32 ans = 0;
|
||||
for (i32 i = 1; i <= 1000; ++i) {
|
||||
for (u32 j = 1; j <= 1000; ++j) {
|
||||
if (coprime[i][j] && right[i] != -1 && right[j] != -1) {
|
||||
ans = max(ans, right[i] + right[j] + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ans == 0)
|
||||
cout << -1;
|
||||
else
|
||||
cout << ans;
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
14
codeforces/827/debug_flags.txt
Normal file
14
codeforces/827/debug_flags.txt
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-g3
|
||||
-fsanitize=address,undefined
|
||||
-fsanitize=float-divide-by-zero
|
||||
-fsanitize=float-cast-overflow
|
||||
-fno-sanitize-recover=all
|
||||
-fstack-protector-all
|
||||
-fstack-usage
|
||||
-fno-omit-frame-pointer
|
||||
-fno-inline
|
||||
-ffunction-sections
|
||||
-D_GLIBCXX_DEBUG
|
||||
-D_GLIBCXX_DEBUG_PEDANTIC
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
128
codeforces/827/e.cc
Normal file
128
codeforces/827/e.cc
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
#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, q;
|
||||
cin >> n >> q;
|
||||
vec<u64> a(n);
|
||||
vec<u64> biggest_step(n + 1, 0), prefix(n + 1, 0);
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> a[i];
|
||||
biggest_step[i + 1] = max(biggest_step[i], a[i]);
|
||||
prefix[i + 1] = prefix[i] + a[i];
|
||||
}
|
||||
u64 k;
|
||||
for (u32 i = 0; i < q; ++i) {
|
||||
cin >> k;
|
||||
|
||||
u32 d =
|
||||
distance(biggest_step.begin(), upper_bound(all(biggest_step), k)) - 1;
|
||||
cout << prefix[d] << " \n"[i == q - 1];
|
||||
}
|
||||
|
||||
// vec<u64> a(n + 1);
|
||||
// a[0] = 0;
|
||||
// for (u32 i = 1; i <= n; ++i) {
|
||||
// cin >> a[i];
|
||||
// a[i] += a[i - 1];
|
||||
// }
|
||||
|
||||
// u64 k;
|
||||
// vec<pair<u64, u32>> questions(q);
|
||||
// vec<u64> ans(q);
|
||||
//
|
||||
// for (u32 i = 0; i < q; ++i) {
|
||||
// cin >> questions[i].ff;
|
||||
// questions[i].ss = i;
|
||||
// }
|
||||
//
|
||||
// sort(all(questions));
|
||||
//
|
||||
// u32 j = 0;
|
||||
// for (auto& [k, i] : questions) {
|
||||
// u32 J = j;
|
||||
// while (J <= n && a[J] <= k + (J ? a[J - 1] : 0))
|
||||
// ++J;
|
||||
//
|
||||
// if (J > j) {
|
||||
// j = J - 1;
|
||||
// }
|
||||
//
|
||||
// ans[i] = a[j];
|
||||
// }
|
||||
//
|
||||
// for (u32 i = 0; i < q; ++i) {
|
||||
// cout << ans[i] << " \n"[i == q - 1];
|
||||
// }
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
124
codeforces/827/f.cc
Normal file
124
codeforces/827/f.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;
|
||||
|
||||
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 q;
|
||||
cin >> q;
|
||||
vec<u64> S(26, 0), T(26, 0);
|
||||
u64 scount = 1, tcount = 1;
|
||||
S[0] = T[0] = 1;
|
||||
u64 cmd, k;
|
||||
string x;
|
||||
for (u64 i = 0; i < q; ++i) {
|
||||
cin >> cmd >> k >> x;
|
||||
if (cmd == 1) {
|
||||
for (auto c : x) {
|
||||
S[c - 'a'] += k;
|
||||
}
|
||||
scount += k * x.size();
|
||||
} else {
|
||||
for (auto c : x) {
|
||||
T[c - 'a'] += k;
|
||||
}
|
||||
tcount += k * x.size();
|
||||
}
|
||||
int loS = 0;
|
||||
while (loS < 26 && S[loS] == 0)
|
||||
++loS;
|
||||
|
||||
int hiT = 25;
|
||||
while (hiT >= 0 && T[hiT] == 0)
|
||||
--hiT;
|
||||
|
||||
bool ok;
|
||||
if (loS < hiT) {
|
||||
ok = true;
|
||||
} else if (loS > hiT) {
|
||||
ok = false;
|
||||
} else {
|
||||
int c = loS;
|
||||
|
||||
bool biggerInS = false;
|
||||
for (int ch = c + 1; ch < 26 && !biggerInS; ++ch)
|
||||
biggerInS = S[ch] > 0;
|
||||
|
||||
if (biggerInS)
|
||||
ok = false;
|
||||
else
|
||||
ok = S[c] < T[c];
|
||||
}
|
||||
|
||||
cout << (ok ? "YES\n" : "NO\n");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
118
codeforces/827/g.cc
Normal file
118
codeforces/827/g.cc
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
#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
|
||||
// }}}
|
||||
|
||||
bitset<2 * 100000 + 1> seen;
|
||||
void solve() {
|
||||
seen.reset();
|
||||
u32 n;
|
||||
cin >> n;
|
||||
vec<u32> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
vec<u32> ans;
|
||||
|
||||
u32 prefix_or = 0;
|
||||
|
||||
for (u32 i = 0; i < 31; ++i) {
|
||||
u32 current_or = prefix_or;
|
||||
i32 index = -1;
|
||||
for (u32 j = 0; j < n; ++j) {
|
||||
if (seen[j])
|
||||
continue;
|
||||
|
||||
if ((prefix_or | a[j]) > current_or) {
|
||||
current_or = prefix_or | a[j];
|
||||
index = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == -1)
|
||||
break;
|
||||
|
||||
ans.push_back(a[index]);
|
||||
seen[index] = true;
|
||||
prefix_or = current_or;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
if (!seen[i]) {
|
||||
ans.push_back(a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cout << ans[i] << " \n"[i == n - 1];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
9
codeforces/827/io/a.in
Normal file
9
codeforces/827/io/a.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
7
|
||||
1 4 3
|
||||
2 5 8
|
||||
9 11 20
|
||||
0 0 0
|
||||
20 20 20
|
||||
4 12 3
|
||||
15 7 8
|
||||
|
||||
10
codeforces/827/io/a.out
Normal file
10
codeforces/827/io/a.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 11.7166 ms
|
||||
7
codeforces/827/io/b.in
Normal file
7
codeforces/827/io/b.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
3
|
||||
4
|
||||
1 1 1 1
|
||||
5
|
||||
8 7 1 3 4
|
||||
1
|
||||
5
|
||||
6
codeforces/827/io/b.out
Normal file
6
codeforces/827/io/b.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
NO
|
||||
YES
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.60322 ms
|
||||
41
codeforces/827/io/c.in
Normal file
41
codeforces/827/io/c.in
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
4
|
||||
|
||||
|
||||
....B...
|
||||
....B...
|
||||
....B...
|
||||
RRRRRRRR
|
||||
....B...
|
||||
....B...
|
||||
....B...
|
||||
....B...
|
||||
|
||||
|
||||
RRRRRRRB
|
||||
B......B
|
||||
B......B
|
||||
B......B
|
||||
B......B
|
||||
B......B
|
||||
B......B
|
||||
RRRRRRRB
|
||||
|
||||
|
||||
RRRRRRBB
|
||||
.B.B..BB
|
||||
RRRRRRBB
|
||||
.B.B..BB
|
||||
.B.B..BB
|
||||
RRRRRRBB
|
||||
.B.B..BB
|
||||
.B.B..BB
|
||||
|
||||
|
||||
........
|
||||
........
|
||||
........
|
||||
RRRRRRRR
|
||||
........
|
||||
........
|
||||
........
|
||||
........
|
||||
7
codeforces/827/io/c.out
Normal file
7
codeforces/827/io/c.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
R
|
||||
B
|
||||
B
|
||||
R
|
||||
|
||||
[code]: 0
|
||||
[time]: 10.8039 ms
|
||||
13
codeforces/827/io/d.in
Normal file
13
codeforces/827/io/d.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
3
|
||||
3 2 1
|
||||
7
|
||||
1 3 5 2 4 7 7
|
||||
5
|
||||
1 2 3 4 5
|
||||
3
|
||||
2 2 4
|
||||
6
|
||||
5 4 3 15 12 16
|
||||
5
|
||||
1 2 2 3 6
|
||||
9
codeforces/827/io/d.out
Normal file
9
codeforces/827/io/d.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
6
|
||||
12
|
||||
9
|
||||
-1
|
||||
10
|
||||
7
|
||||
|
||||
[code]: 0
|
||||
[time]: 107.307 ms
|
||||
10
codeforces/827/io/e.in
Normal file
10
codeforces/827/io/e.in
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
3
|
||||
4 5
|
||||
1 2 1 5
|
||||
1 2 4 9 10
|
||||
2 2
|
||||
1 1
|
||||
0 1
|
||||
3 1
|
||||
1000000000 1000000000 1000000000
|
||||
1000000000
|
||||
6
codeforces/827/io/e.out
Normal file
6
codeforces/827/io/e.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
1 4 4 9 9
|
||||
0 2
|
||||
3000000000
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.2367 ms
|
||||
14
codeforces/827/io/f.in
Normal file
14
codeforces/827/io/f.in
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
3
|
||||
5
|
||||
2 1 aa
|
||||
1 2 a
|
||||
2 3 a
|
||||
1 2 b
|
||||
2 3 abca
|
||||
2
|
||||
1 5 mihai
|
||||
2 2 buiucani
|
||||
3
|
||||
1 5 b
|
||||
2 3 a
|
||||
2 4 paiu
|
||||
13
codeforces/827/io/f.out
Normal file
13
codeforces/827/io/f.out
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.97944 ms
|
||||
11
codeforces/827/io/g.in
Normal file
11
codeforces/827/io/g.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
4
|
||||
1 2 4 8
|
||||
7
|
||||
5 1 2 3 4 5 5
|
||||
2
|
||||
1 101
|
||||
6
|
||||
2 3 4 2 3 4
|
||||
8
|
||||
1 4 2 3 4 5 7 1
|
||||
8
codeforces/827/io/g.out
Normal file
8
codeforces/827/io/g.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
8 4 2 1
|
||||
5 2 1 3 4 5 5
|
||||
101 1
|
||||
4 3 2 2 3 4
|
||||
7 1 4 2 3 4 5 1
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.94392 ms
|
||||
30
codeforces/827/makefile
Normal file
30
codeforces/827/makefile
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
.PHONY: run debug clean setup init
|
||||
|
||||
VERSION ?= 20
|
||||
|
||||
SRC = $(word 2,$(MAKECMDGOALS))
|
||||
|
||||
.SILENT:
|
||||
|
||||
run:
|
||||
sh scripts/run.sh $(SRC)
|
||||
|
||||
debug:
|
||||
sh scripts/debug.sh $(SRC)
|
||||
|
||||
clean:
|
||||
rm -rf build/*
|
||||
|
||||
setup:
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
test -d scripts || mkdir -p scripts
|
||||
test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format .
|
||||
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt
|
||||
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
|
||||
|
||||
init:
|
||||
make setup
|
||||
|
||||
%:
|
||||
@:
|
||||
29
codeforces/827/scripts/debug.sh
Normal file
29
codeforces/827/scripts/debug.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./scripts/utils.sh
|
||||
|
||||
SRC="$1"
|
||||
BASE=$(basename "$SRC" .cc)
|
||||
INPUT="${BASE}.in"
|
||||
OUTPUT="${BASE}.out"
|
||||
DBG_BIN="${BASE}.debug"
|
||||
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
|
||||
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||
|
||||
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||
|
||||
INPUT="io/$INPUT"
|
||||
OUTPUT="io/$OUTPUT"
|
||||
DBG_BIN="build/$DBG_BIN"
|
||||
|
||||
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
|
||||
CODE=$?
|
||||
test $CODE -gt 0 && exit $CODE
|
||||
|
||||
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
|
||||
exit $?
|
||||
29
codeforces/827/scripts/run.sh
Normal file
29
codeforces/827/scripts/run.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ./scripts/utils.sh
|
||||
|
||||
SRC="$1"
|
||||
BASE=$(basename "$SRC" .cc)
|
||||
INPUT="${BASE}.in"
|
||||
OUTPUT="${BASE}.out"
|
||||
RUN_BIN="${BASE}.run"
|
||||
|
||||
test -d build || mkdir -p build
|
||||
test -d io || mkdir -p io
|
||||
|
||||
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||
|
||||
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||
|
||||
INPUT="io/$INPUT"
|
||||
OUTPUT="io/$OUTPUT"
|
||||
RUN_BIN="build/$RUN_BIN"
|
||||
|
||||
compile_source "$SRC" "$RUN_BIN" "$OUTPUT" ""
|
||||
CODE=$?
|
||||
test $CODE -gt 0 && exit $CODE
|
||||
|
||||
execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT"
|
||||
exit $?
|
||||
53
codeforces/827/scripts/utils.sh
Normal file
53
codeforces/827/scripts/utils.sh
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#!/bin/sh
|
||||
|
||||
execute_binary() {
|
||||
binary="$1"
|
||||
input="$2"
|
||||
output="$3"
|
||||
|
||||
start=$(date '+%s.%N')
|
||||
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
CODE=$?
|
||||
end=$(date '+%s.%N')
|
||||
truncate -s "$(head -n 1000 "$output" | wc -c)" "$output"
|
||||
|
||||
if [ $CODE -ge 124 ]; then
|
||||
MSG=''
|
||||
case $CODE in
|
||||
124) MSG='TIMEOUT' ;;
|
||||
128) MSG='SIGILL' ;;
|
||||
130) MSG='SIGABRT' ;;
|
||||
131) MSG='SIGBUS' ;;
|
||||
136) MSG='SIGFPE' ;;
|
||||
135) MSG='SIGSEGV' ;;
|
||||
137) MSG='SIGPIPE' ;;
|
||||
139) MSG='SIGTERM' ;;
|
||||
esac
|
||||
[ $CODE -ne 124 ] && sed -i '$d' "$output"
|
||||
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
|
||||
else
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
fi
|
||||
|
||||
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
|
||||
return $CODE
|
||||
}
|
||||
|
||||
compile_source() {
|
||||
src="$1"
|
||||
bin="$2"
|
||||
output="$3"
|
||||
flags="$4"
|
||||
|
||||
test -f "$bin" && rm "$bin" || true
|
||||
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
|
||||
CODE=$?
|
||||
|
||||
if [ $CODE -gt 0 ]; then
|
||||
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||
return $CODE
|
||||
else
|
||||
echo '' >"$output"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue