feat: 806
This commit is contained in:
parent
579760f0f8
commit
98ea573f5a
73 changed files with 2821 additions and 0 deletions
9
codeforces/918/.clang-format
Normal file
9
codeforces/918/.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
|
||||
42
codeforces/918/.clangd
Normal file
42
codeforces/918/.clangd
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
-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
|
||||
-e -std=c++23
|
||||
-e -std=c++23
|
||||
100
codeforces/918/a.cc
Normal file
100
codeforces/918/a.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() {
|
||||
u32 a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
|
||||
u32 ans;
|
||||
// NOTE: ngl didn't even check if this was right lol
|
||||
if (a == b) {
|
||||
ans = c;
|
||||
}
|
||||
if (a == c) {
|
||||
ans = b;
|
||||
}
|
||||
|
||||
if (b == c) {
|
||||
ans = a;
|
||||
}
|
||||
|
||||
println("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
98
codeforces/918/b.cc
Normal file
98
codeforces/918/b.cc
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#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() {
|
||||
vec<string> grid(3);
|
||||
for (auto& e : grid)
|
||||
cin >> e;
|
||||
|
||||
for (auto& row : grid) {
|
||||
if (row.find('?') == string::npos)
|
||||
continue;
|
||||
|
||||
for (auto c : "ABC") {
|
||||
if (row.find(c) == string::npos) {
|
||||
println("{}", c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
102
codeforces/918/c.cc
Normal file
102
codeforces/918/c.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
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n;
|
||||
cin >> n;
|
||||
vec<u32> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
u64 total = accumulate(all(a), 0LL);
|
||||
|
||||
// NOTE: used auto and float, WA
|
||||
u64 root = sqrtl(total);
|
||||
while (root * root < total) {
|
||||
++root;
|
||||
}
|
||||
|
||||
if (root * root == total) {
|
||||
YES();
|
||||
} else {
|
||||
NO();
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
31
codeforces/918/compile_flags.txt
Normal file
31
codeforces/918/compile_flags.txt
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
-pedantic-errors
|
||||
-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
|
||||
108
codeforces/918/d.cc
Normal file
108
codeforces/918/d.cc
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#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;
|
||||
|
||||
// idea: can form valid word, greedy
|
||||
// CV, CVC
|
||||
// working backwards is easier
|
||||
|
||||
string ans;
|
||||
// NOTE: control flow took a second
|
||||
for (i32 i = n - 1; i >= 0; --i) {
|
||||
ans.push_back(s[i]);
|
||||
ans.push_back(s[i - 1]);
|
||||
if (!(s[i] == 'e' || s[i] == 'a')) {
|
||||
ans.push_back(s[i - 2]);
|
||||
--i;
|
||||
}
|
||||
--i;
|
||||
if (i > 0)
|
||||
ans.push_back('.');
|
||||
}
|
||||
|
||||
reverse(all(ans));
|
||||
println("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
14
codeforces/918/debug_flags.txt
Normal file
14
codeforces/918/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
|
||||
129
codeforces/918/e.cc
Normal file
129
codeforces/918/e.cc
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
#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() {
|
||||
/*
|
||||
want sum(o[l:r])==sum(e[l:r])
|
||||
|
||||
for every r:
|
||||
opref[r] - opref[l] == epref[r] - epref[l]
|
||||
opref[r] - epref[r] == opref[l] - epref[l]
|
||||
^ known O(1) ^ insert in tree
|
||||
*/
|
||||
u32 n;
|
||||
cin >> n;
|
||||
|
||||
vec<i64> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
if (n == 1) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: missed initial array
|
||||
// NOTE: had a major problem with your ideas
|
||||
// "oh just change the sign, my logic is not right"
|
||||
// TRUST YOUR LOGIC, BUT NOT THE IMPL - IMPL != IDEA
|
||||
set<i64> pref{0};
|
||||
i64 acc = 0;
|
||||
|
||||
for (u32 r = 1; r <= n; ++r) {
|
||||
if (r & 1) {
|
||||
acc += a[r - 1];
|
||||
} else {
|
||||
acc -= a[r - 1];
|
||||
}
|
||||
|
||||
// dbln("r={}, o={} e={}", r, o, e);
|
||||
|
||||
// NOTE: had this backwards, and honestly idk even why
|
||||
if (pref.find(acc) != pref.end()) {
|
||||
YES();
|
||||
return;
|
||||
}
|
||||
|
||||
pref.insert(acc);
|
||||
}
|
||||
|
||||
NO();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
114
codeforces/918/f.cc
Normal file
114
codeforces/918/f.cc
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#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
|
||||
// }}}
|
||||
|
||||
i64 inv_merge(vector<i64>& a, vector<i64>& tmp) {
|
||||
if (r - l <= 1)
|
||||
return 0;
|
||||
int m = (l + r) >> 1;
|
||||
i64 ans = inv_merge(a, tmp, l, m) + inv_merge(a, tmp, m, r);
|
||||
int i = l, j = m, k = l;
|
||||
while (i < m || j < r) {
|
||||
if (j == r || (i < m && a[i] <= a[j]))
|
||||
tmp[k++] = a[i++];
|
||||
else {
|
||||
tmp[k++] = a[j++];
|
||||
ans += (m - i);
|
||||
}
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
void solve() {
|
||||
// NOTE: erroneosouyl thought was interval overlaps (even that took too long
|
||||
// to code) should've stayed at it and continued, but was tired/acted tired
|
||||
// consider the problem statemnt & examples more slowly
|
||||
// simplifcation: count the inversions
|
||||
i32 n;
|
||||
cin >> n;
|
||||
vector<pair<i64, i64>> p(n);
|
||||
for (i32 i = 0; i < n; ++i)
|
||||
cin >> p[i].first >> p[i].second;
|
||||
sort(all(p));
|
||||
vector<i64> b(n), tmp(n);
|
||||
for (i32 i = 0; i < n; ++i)
|
||||
b[i] = p[i].second;
|
||||
println("{}", inv_merge(b, tmp, 0, n));
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
128
codeforces/918/g.cc
Normal file
128
codeforces/918/g.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, m;
|
||||
cin >> n >> m;
|
||||
vec<vec<pair<u32, u32>>> graph(n + 1);
|
||||
for (u32 i = 0; i < m; ++i) {
|
||||
u32 u, v, w;
|
||||
cin >> u >> v >> w;
|
||||
graph[u].push_back({v, w});
|
||||
graph[v].push_back({u, w});
|
||||
}
|
||||
vec<u32> s(n + 1);
|
||||
for (u32 i = 1; i <= n; ++i)
|
||||
cin >> s[i];
|
||||
|
||||
const i64 INF = static_cast<i64>(4e18);
|
||||
vec<vec<i64>> dist(n + 1, vec<i64>(1001, INF));
|
||||
using T = tuple<i64, u32, u32>;
|
||||
priority_queue<T, vec<T>, greater<T>> pq;
|
||||
|
||||
u32 b0 = s[1];
|
||||
dist[1][b0] = 0;
|
||||
pq.emplace(0, 1, b0);
|
||||
|
||||
while (!pq.empty()) {
|
||||
auto [t, u, b] = pq.top();
|
||||
pq.pop();
|
||||
if (t != dist[u][b])
|
||||
continue;
|
||||
u32 nb = min(b, s[u]);
|
||||
if (nb < b && t < dist[u][nb]) {
|
||||
dist[u][nb] = t;
|
||||
pq.emplace(t, u, nb);
|
||||
}
|
||||
for (auto [v, w] : graph[u]) {
|
||||
i64 nt = t + static_cast<i64>(w) * static_cast<i64>(b);
|
||||
if (nt < dist[v][b]) {
|
||||
dist[v][b] = nt;
|
||||
pq.emplace(nt, v, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i64 ans = INF;
|
||||
for (u32 b = 1; b <= 1000; ++b)
|
||||
ans = min(ans, dist[n][b]);
|
||||
cout << ans << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
std::cin.exceptions(std::cin.failbit);
|
||||
|
||||
#ifdef LOCAL
|
||||
std::cerr.rdbuf(std::cout.rdbuf());
|
||||
std::cout.setf(std::ios::unitbuf);
|
||||
std::cerr.setf(std::ios::unitbuf);
|
||||
#else
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
#endif
|
||||
|
||||
u32 tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/918/io/a.in
Normal file
11
codeforces/918/io/a.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10
|
||||
1 2 2
|
||||
4 3 4
|
||||
5 5 6
|
||||
7 8 8
|
||||
9 0 9
|
||||
3 6 3
|
||||
2 8 2
|
||||
5 7 7
|
||||
7 7 5
|
||||
5 7 5
|
||||
14
codeforces/918/io/a.out
Normal file
14
codeforces/918/io/a.out
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
1
|
||||
3
|
||||
6
|
||||
7
|
||||
0
|
||||
6
|
||||
8
|
||||
5
|
||||
5
|
||||
7
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.48575 ms
|
||||
[debug]: false
|
||||
10
codeforces/918/io/b.in
Normal file
10
codeforces/918/io/b.in
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
3
|
||||
ABC
|
||||
C?B
|
||||
BCA
|
||||
BCA
|
||||
CA?
|
||||
ABC
|
||||
?AB
|
||||
BCA
|
||||
ABC
|
||||
7
codeforces/918/io/b.out
Normal file
7
codeforces/918/io/b.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
A
|
||||
B
|
||||
C
|
||||
|
||||
[code]: 0
|
||||
[time]: 5.89085 ms
|
||||
[debug]: false
|
||||
11
codeforces/918/io/c.in
Normal file
11
codeforces/918/io/c.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
1
|
||||
9
|
||||
2
|
||||
14 2
|
||||
7
|
||||
1 2 3 4 5 6 7
|
||||
6
|
||||
1 3 5 7 9 11
|
||||
4
|
||||
2 2 2 2
|
||||
9
codeforces/918/io/c.out
Normal file
9
codeforces/918/io/c.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
NO
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 6.36053 ms
|
||||
[debug]: false
|
||||
13
codeforces/918/io/d.in
Normal file
13
codeforces/918/io/d.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
8
|
||||
bacedbab
|
||||
4
|
||||
baba
|
||||
13
|
||||
daddecabeddad
|
||||
3
|
||||
dac
|
||||
6
|
||||
dacdac
|
||||
22
|
||||
dababbabababbabbababba
|
||||
10
codeforces/918/io/d.out
Normal file
10
codeforces/918/io/d.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
ba.ced.bab
|
||||
ba.ba
|
||||
dad.de.ca.bed.dad
|
||||
dac
|
||||
dac.dac
|
||||
da.bab.ba.ba.bab.bab.ba.bab.ba
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.4178 ms
|
||||
[debug]: false
|
||||
13
codeforces/918/io/e.in
Normal file
13
codeforces/918/io/e.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
3
|
||||
1 3 2
|
||||
6
|
||||
1 1 1 1 1 1
|
||||
10
|
||||
1 6 9 8 55 3 14 2 7 2
|
||||
8
|
||||
1 2 11 4 1 5 1 2
|
||||
6
|
||||
2 6 1 5 7 8
|
||||
9
|
||||
2 5 10 4 4 9 6 7 8
|
||||
10
codeforces/918/io/e.out
Normal file
10
codeforces/918/io/e.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
YES
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
[time]: 9.7537 ms
|
||||
[debug]: false
|
||||
27
codeforces/918/io/f.in
Normal file
27
codeforces/918/io/f.in
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
5
|
||||
2
|
||||
2 3
|
||||
1 4
|
||||
6
|
||||
2 6
|
||||
3 9
|
||||
4 5
|
||||
1 8
|
||||
7 10
|
||||
-2 100
|
||||
4
|
||||
-10 10
|
||||
-5 5
|
||||
-12 12
|
||||
-13 13
|
||||
5
|
||||
-4 9
|
||||
-2 5
|
||||
3 4
|
||||
6 7
|
||||
8 10
|
||||
4
|
||||
1 2
|
||||
3 4
|
||||
5 6
|
||||
7 8
|
||||
30
codeforces/918/io/f.out
Normal file
30
codeforces/918/io/f.out
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
f.cc: In function ‘i64 inv_merge(std::vector<long int>&, std::vector<long int>&)’:
|
||||
f.cc:61:7: error: ‘r’ was not declared in this scope
|
||||
61 | if (r - l <= 1)
|
||||
| ^
|
||||
f.cc:61:11: error: ‘l’ was not declared in this scope
|
||||
61 | if (r - l <= 1)
|
||||
| ^
|
||||
f.cc:63:12: error: ‘l’ was not declared in this scope
|
||||
63 | int m = (l + r) >> 1;
|
||||
| ^
|
||||
f.cc:63:16: error: ‘r’ was not declared in this scope
|
||||
63 | int m = (l + r) >> 1;
|
||||
| ^
|
||||
f.cc: In function ‘void solve()’:
|
||||
f.cc:91:26: error: too many arguments to function ‘i64 inv_merge(std::vector<long int>&, std::vector<long int>&)’
|
||||
91 | println("{}", inv_merge(b, tmp, 0, n));
|
||||
| ~~~~~~~~~^~~~~~~~~~~~~~
|
||||
f.cc:60:5: note: declared here
|
||||
60 | i64 inv_merge(vector<i64>& a, vector<i64>& tmp) {
|
||||
| ^~~~~~~~~
|
||||
f.cc: At global scope:
|
||||
f.cc:39:13: warning: ‘void YES()’ defined but not used [-Wunused-function]
|
||||
39 | static void YES() {
|
||||
| ^~~
|
||||
f.cc:35:13: warning: ‘void NO()’ defined but not used [-Wunused-function]
|
||||
35 | static void NO() {
|
||||
| ^~
|
||||
cc1plus: note: unrecognized command-line option ‘-Wno-sign-promotion’ may have been intended to silence earlier diagnostics
|
||||
|
||||
[code]: 1
|
||||
32
codeforces/918/io/g.in
Normal file
32
codeforces/918/io/g.in
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
3
|
||||
5 5
|
||||
1 2 2
|
||||
3 2 1
|
||||
2 4 5
|
||||
2 5 7
|
||||
4 5 1
|
||||
5 2 1 3 3
|
||||
5 10
|
||||
1 2 5
|
||||
1 3 5
|
||||
1 4 4
|
||||
1 5 8
|
||||
2 3 6
|
||||
2 4 3
|
||||
2 5 2
|
||||
3 4 1
|
||||
3 5 8
|
||||
4 5 2
|
||||
7 2 8 4 1
|
||||
7 10
|
||||
3 2 8
|
||||
2 1 4
|
||||
2 5 7
|
||||
2 6 4
|
||||
7 1 2
|
||||
4 3 5
|
||||
6 4 2
|
||||
6 7 1
|
||||
6 7 4
|
||||
4 5 9
|
||||
7 6 5 4 3 2 1
|
||||
7
codeforces/918/io/g.out
Normal file
7
codeforces/918/io/g.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
19
|
||||
36
|
||||
14
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.39873 ms
|
||||
[debug]: false
|
||||
30
codeforces/918/makefile
Normal file
30
codeforces/918/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/918/scripts/debug.sh
Normal file
29
codeforces/918/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" true
|
||||
exit $?
|
||||
29
codeforces/918/scripts/run.sh
Normal file
29
codeforces/918/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 $?
|
||||
61
codeforces/918/scripts/utils.sh
Normal file
61
codeforces/918/scripts/utils.sh
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/sh
|
||||
|
||||
execute_binary() {
|
||||
binary="$1"
|
||||
input="$2"
|
||||
output="$3"
|
||||
is_debug="$4"
|
||||
|
||||
start=$(date '+%s.%N')
|
||||
if [ -n "$is_debug" ]; then
|
||||
asan="$(ldconfig -p | grep libasan.so | head -n1 | awk '{print $4}')"
|
||||
LD_PRELOAD="$asan" timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
else
|
||||
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||
fi
|
||||
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
|
||||
test -n "$is_debug" && is_debug_string=true || is_debug_string=false
|
||||
printf '\n[debug]: %s' "$is_debug_string" >>$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