1043
This commit is contained in:
parent
2a8ecba5b9
commit
8a3884da87
27 changed files with 1054 additions and 0 deletions
9
codeforces/1043/.clang-format
Normal file
9
codeforces/1043/.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
|
||||
41
codeforces/1043/.clangd
Normal file
41
codeforces/1043/.clangd
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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
|
||||
96
codeforces/1043/a.cc
Normal file
96
codeforces/1043/a.cc
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#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 a;
|
||||
cin >> a;
|
||||
cin >> n;
|
||||
string b, c;
|
||||
cin >> b >> c;
|
||||
|
||||
string o;
|
||||
for (u32 i = 0; i < b.size(); ++i) {
|
||||
if (c[i] == 'D') {
|
||||
a += b[i];
|
||||
} else {
|
||||
o += b[i];
|
||||
}
|
||||
}
|
||||
|
||||
reverse(all(o));
|
||||
|
||||
println("{}", o + a);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
99
codeforces/1043/b.cc
Normal file
99
codeforces/1043/b.cc
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#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() {
|
||||
u64 n;
|
||||
cin >> n;
|
||||
|
||||
vec<u64> ans;
|
||||
|
||||
u64 ten_power = 1;
|
||||
for (u32 a = 1; a <= 18; ++a) {
|
||||
ten_power *= 10;
|
||||
if (n % (ten_power + 1)) {
|
||||
continue;
|
||||
} else {
|
||||
ans.push_back(n / (ten_power + 1));
|
||||
}
|
||||
}
|
||||
|
||||
// unecessary
|
||||
sort(all(ans));
|
||||
|
||||
cout << ans.size() << '\n';
|
||||
|
||||
for (u32 i = 0; i < ans.size(); ++i) {
|
||||
cout << ans[i] << " \n"[i == ans.size() - 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;
|
||||
}
|
||||
// }}}
|
||||
104
codeforces/1043/c.cc
Normal file
104
codeforces/1043/c.cc
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#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() {
|
||||
i64 n;
|
||||
cin >> n;
|
||||
|
||||
map<i64, u64> w2c;
|
||||
for (u32 x = 0; x <= 19; ++x) {
|
||||
w2c[(i64)powl(3, x)] = (u64)powl(3, x + 1) + x * (u64)powl(3, x - 1);
|
||||
}
|
||||
|
||||
u64 ans = 0, deals = 0;
|
||||
|
||||
// for (auto it = w2c.begin(); it != w2c.end(); ++it) {
|
||||
// print("w: {} cost: {}; ", it->first, it->second);
|
||||
// }
|
||||
// println();
|
||||
|
||||
for (auto it = w2c.rbegin(); it != w2c.rend(); ++it) {
|
||||
auto w = it->first;
|
||||
auto c = it->second;
|
||||
while (n >= w) {
|
||||
// println("bought {} watermelons at cost {}", w, c);
|
||||
ans += c;
|
||||
n -= w;
|
||||
++deals;
|
||||
}
|
||||
}
|
||||
|
||||
println("{}", ans);
|
||||
// println("{} {}", ans, deals);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
115
codeforces/1043/c2.cc
Normal file
115
codeforces/1043/c2.cc
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#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() {
|
||||
i64 n, k;
|
||||
cin >> n >> k;
|
||||
|
||||
vec<i64> costs(20);
|
||||
for (u32 x = 0; x <= 19; ++x) {
|
||||
costs[x] = (i64)powl(3, x + 1) + x * (i64)powl(3, x - 1);
|
||||
}
|
||||
|
||||
i64 cost = 0;
|
||||
|
||||
vec<i64> deals(costs.size(), 0);
|
||||
|
||||
for (i32 i = costs.size() - 1; i >= 0; --i) {
|
||||
auto w = (u64)powl(3, i);
|
||||
auto times = n / w;
|
||||
n -= w * times;
|
||||
cost += costs[i] * times;
|
||||
deals[i] += times;
|
||||
}
|
||||
|
||||
i64 left = k - accumulate(all(deals), 0LL);
|
||||
|
||||
if (left < 0) {
|
||||
println("-1");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i32 i = costs.size() - 1; left > 0 && i > 0; --i) {
|
||||
i64 y = min(left / 2, deals[i]);
|
||||
|
||||
left -= 2 * y;
|
||||
cost -= y * costs[i];
|
||||
cost += 3 * y * costs[i - 1];
|
||||
|
||||
deals[i] -= y;
|
||||
deals[i - 1] += 3 * y;
|
||||
}
|
||||
|
||||
println("{}", cost);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
31
codeforces/1043/compile_flags.txt
Normal file
31
codeforces/1043/compile_flags.txt
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
-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
|
||||
-std=c++23
|
||||
116
codeforces/1043/d.cc
Normal file
116
codeforces/1043/d.cc
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <typename T>
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
#endif
|
||||
|
||||
static void NO() {
|
||||
std::cout << "NO\n";
|
||||
}
|
||||
|
||||
static void YES() {
|
||||
std::cout << "YES\n";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
const int MAXD = 18;
|
||||
u64 POW10[MAXD], PREF[MAXD];
|
||||
|
||||
u64 digit_prefix_sum(u64 n) {
|
||||
if (n < 10)
|
||||
return n * (n + 1) / 2;
|
||||
int d = 0;
|
||||
while (POW10[d + 1] <= n)
|
||||
++d;
|
||||
u64 p = POW10[d];
|
||||
u64 msd = n / p;
|
||||
u64 rest = n % p;
|
||||
return msd * PREF[d] + (msd * (msd - 1) / 2) * p + msd * (rest + 1) +
|
||||
digit_prefix_sum(rest);
|
||||
}
|
||||
|
||||
void solve() {
|
||||
u64 k;
|
||||
cin >> k;
|
||||
u64 K = k, D = 1;
|
||||
for (u32 i = 0; i < 15; ++i) {
|
||||
u64 base_count = (POW10[i + 1] - POW10[i]) * (i + 1);
|
||||
if (base_count > K) {
|
||||
D = i + 1;
|
||||
break;
|
||||
}
|
||||
K -= base_count;
|
||||
}
|
||||
u64 ans = 0;
|
||||
u64 x = POW10[D - 1] + K / D - 1;
|
||||
if (K % D) {
|
||||
u64 next = x + 1;
|
||||
for (u32 i = 0; i < D - (K % D); ++i)
|
||||
next /= 10;
|
||||
while (next) {
|
||||
ans += next % 10;
|
||||
next /= 10;
|
||||
}
|
||||
}
|
||||
ans += digit_prefix_sum(x);
|
||||
cout << ans << "\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/1043/debug_flags.txt
Normal file
14
codeforces/1043/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
|
||||
118
codeforces/1043/e.cc
Normal file
118
codeforces/1043/e.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
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
u32 n, m, q;
|
||||
cin >> n >> m >> q;
|
||||
|
||||
vec<u64> a(n), b(m);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
for (auto& e : b)
|
||||
cin >> e;
|
||||
sort(rall(a));
|
||||
sort(rall(b));
|
||||
|
||||
vec<u32> counts(n + m + 1, 0);
|
||||
vec<u64> prefix_a(n + 1, 0), prefix_b(m + 1, 0);
|
||||
for (u32 i = 1; i <= n; ++i) {
|
||||
prefix_a[i] = prefix_a[i - 1] + a[i - 1];
|
||||
}
|
||||
for (u32 i = 1; i <= m; ++i) {
|
||||
prefix_b[i] = prefix_b[i - 1] + b[i - 1];
|
||||
}
|
||||
|
||||
i32 i = 0, j = 0;
|
||||
|
||||
for (u32 index = 1; index <= n + m; ++index) {
|
||||
counts[index] = counts[index - 1];
|
||||
if (j >= m || a[i] >= b[j]) {
|
||||
++counts[index];
|
||||
++i;
|
||||
} else {
|
||||
++j;
|
||||
}
|
||||
}
|
||||
|
||||
u32 x, y, z;
|
||||
for (u32 i = 0; i < q; ++i) {
|
||||
cin >> x >> y >> z;
|
||||
u32 lo = (z > y) ? (z - y) : 0;
|
||||
u32 hi = min(x, z);
|
||||
u32 take_a = clamp(counts[z], lo, hi);
|
||||
u32 take_b = z - take_a;
|
||||
|
||||
println("{}", prefix_a[take_a] + prefix_b[take_b]);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
15
codeforces/1043/file
Normal file
15
codeforces/1043/file
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
0
|
||||
70
|
||||
64
|
||||
39
|
||||
57
|
||||
2700000000
|
||||
4200000000
|
||||
420
|
||||
711
|
||||
711
|
||||
0
|
||||
997
|
||||
0
|
||||
1360
|
||||
|
||||
21
codeforces/1043/io/a.in
Normal file
21
codeforces/1043/io/a.in
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
4
|
||||
2
|
||||
ot
|
||||
2
|
||||
ad
|
||||
DV
|
||||
3
|
||||
efo
|
||||
7
|
||||
rdcoecs
|
||||
DVDVDVD
|
||||
3
|
||||
aca
|
||||
4
|
||||
bbaa
|
||||
DVDV
|
||||
3
|
||||
biz
|
||||
4
|
||||
abon
|
||||
VVDD
|
||||
8
codeforces/1043/io/a.out
Normal file
8
codeforces/1043/io/a.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
dota
|
||||
codeforces
|
||||
abacaba
|
||||
babizon
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.89187 ms
|
||||
[debug]: false
|
||||
6
codeforces/1043/io/b.in
Normal file
6
codeforces/1043/io/b.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5
|
||||
1111
|
||||
12
|
||||
55
|
||||
999999999999999999
|
||||
1000000000000000000
|
||||
12
codeforces/1043/io/b.out
Normal file
12
codeforces/1043/io/b.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
2
|
||||
11 101
|
||||
0
|
||||
1
|
||||
5
|
||||
3
|
||||
999999999 999000999000999 90909090909090909
|
||||
0
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.21372 ms
|
||||
[debug]: false
|
||||
9
codeforces/1043/io/c.in
Normal file
9
codeforces/1043/io/c.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
7
|
||||
1
|
||||
3
|
||||
8
|
||||
2
|
||||
10
|
||||
20
|
||||
260010000
|
||||
|
||||
11
codeforces/1043/io/c.out
Normal file
11
codeforces/1043/io/c.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
3
|
||||
10
|
||||
26
|
||||
6
|
||||
36
|
||||
72
|
||||
2250964728
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.50387 ms
|
||||
[debug]: false
|
||||
10
codeforces/1043/io/c2.in
Normal file
10
codeforces/1043/io/c2.in
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
8
|
||||
1 1
|
||||
3 3
|
||||
8 3
|
||||
2 4
|
||||
10 10
|
||||
20 14
|
||||
3 2
|
||||
9 1
|
||||
|
||||
12
codeforces/1043/io/c2.out
Normal file
12
codeforces/1043/io/c2.out
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
3
|
||||
9
|
||||
-1
|
||||
6
|
||||
30
|
||||
63
|
||||
10
|
||||
33
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.52867 ms
|
||||
[debug]: false
|
||||
8
codeforces/1043/io/d.in
Normal file
8
codeforces/1043/io/d.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
7
|
||||
5
|
||||
10
|
||||
13
|
||||
29
|
||||
1000000000
|
||||
1000000000000000
|
||||
12
|
||||
5
codeforces/1043/io/d.out
Normal file
5
codeforces/1043/io/d.out
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
timeout: the monitored command dumped core
|
||||
|
||||
[code]: 136 (SIGFPE)
|
||||
[time]: 81.4447 ms
|
||||
[debug]: false
|
||||
27
codeforces/1043/io/e.in
Normal file
27
codeforces/1043/io/e.in
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
4
|
||||
3 4 5
|
||||
10 20 30
|
||||
1 2 3 4
|
||||
0 0 0
|
||||
3 4 7
|
||||
3 4 4
|
||||
1 4 4
|
||||
2 2 4
|
||||
5 5 2
|
||||
500000000 300000000 100000000 900000000 700000000
|
||||
800000000 400000000 1000000000 600000000 200000000
|
||||
1 4 3
|
||||
5 2 6
|
||||
4 4 1
|
||||
100 100 20 20
|
||||
100 100 20 20
|
||||
4 4 5
|
||||
3 3 6
|
||||
2 363 711
|
||||
286 121 102
|
||||
1 1 1
|
||||
3 1 1
|
||||
1 2 0
|
||||
1 3 2
|
||||
0 1 0
|
||||
3 3 3
|
||||
18
codeforces/1043/io/e.out
Normal file
18
codeforces/1043/io/e.out
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
0
|
||||
70
|
||||
64
|
||||
39
|
||||
57
|
||||
2700000000
|
||||
4200000000
|
||||
420
|
||||
711
|
||||
711
|
||||
0
|
||||
997
|
||||
0
|
||||
1360
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.03102 ms
|
||||
[debug]: false
|
||||
30
codeforces/1043/makefile
Normal file
30
codeforces/1043/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/1043/scripts/debug.sh
Normal file
29
codeforces/1043/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/1043/scripts/run.sh
Normal file
29
codeforces/1043/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/1043/scripts/utils.sh
Normal file
61
codeforces/1043/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