935
This commit is contained in:
parent
02046fbdf6
commit
bbb475ed71
26 changed files with 1072 additions and 0 deletions
9
codeforces/935/.clang-format
Normal file
9
codeforces/935/.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
|
||||||
39
codeforces/935/.clangd
Normal file
39
codeforces/935/.clangd
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
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
|
||||||
110
codeforces/935/a.cc
Normal file
110
codeforces/935/a.cc
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
#include <version>
|
||||||
|
#ifdef __cpp_lib_ranges_enumerate
|
||||||
|
#include <ranges>
|
||||||
|
namespace rv = std::views;
|
||||||
|
namespace rs = std::ranges;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 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 = a + b / 3;
|
||||||
|
|
||||||
|
b -= 3 * (b / 3);
|
||||||
|
|
||||||
|
if (b > 0) {
|
||||||
|
if (b + c >= 3) {
|
||||||
|
c -= 3 - b;
|
||||||
|
++ans;
|
||||||
|
} else {
|
||||||
|
cout << "-1\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ans += ceil(c / 3.0);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
95
codeforces/935/b.cc
Normal file
95
codeforces/935/b.cc
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
#include <version>
|
||||||
|
#ifdef __cpp_lib_ranges_enumerate
|
||||||
|
#include <ranges>
|
||||||
|
namespace rv = std::views;
|
||||||
|
namespace rs = std::ranges;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 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 a, b, m;
|
||||||
|
cin >> a >> b >> m;
|
||||||
|
|
||||||
|
u64 ans = (m + 1 + a - 1) / a + (m + 1 + b - 1) / b;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
129
codeforces/935/c.cc
Normal file
129
codeforces/935/c.cc
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
#include <version>
|
||||||
|
#ifdef __cpp_lib_ranges_enumerate
|
||||||
|
#include <ranges>
|
||||||
|
namespace rv = std::views;
|
||||||
|
namespace rs = std::ranges;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 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() {
|
||||||
|
i32 n;
|
||||||
|
cin >> n;
|
||||||
|
string s;
|
||||||
|
cin >> s;
|
||||||
|
|
||||||
|
u32 zero = 0;
|
||||||
|
u32 one = count_if(all(s), [](char c) {
|
||||||
|
return c == '1';
|
||||||
|
});
|
||||||
|
|
||||||
|
i32 best_index = n;
|
||||||
|
f64 best_score = n;
|
||||||
|
for (i32 i = 0; i <= n; ++i) {
|
||||||
|
if (i > 0) {
|
||||||
|
zero += (s[i - 1] == '0');
|
||||||
|
one -= (s[i - 1] == '1');
|
||||||
|
}
|
||||||
|
auto left_count = i;
|
||||||
|
auto right_count = n - left_count;
|
||||||
|
bool valid =
|
||||||
|
zero >= (left_count + 2 - 1) / 2 && one >= (right_count + 2 - 1) / 2;
|
||||||
|
|
||||||
|
if (!valid) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto score = abs(n / 2.0 - i);
|
||||||
|
|
||||||
|
if (score <= best_score) {
|
||||||
|
if (score == best_score) {
|
||||||
|
best_index = min(best_index, i);
|
||||||
|
} else {
|
||||||
|
best_index = i;
|
||||||
|
}
|
||||||
|
best_score = score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println("{}", best_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
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/935/compile_flags.txt
Normal file
31
codeforces/935/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
|
||||||
118
codeforces/935/d.cc
Normal file
118
codeforces/935/d.cc
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
#include <version>
|
||||||
|
#ifdef __cpp_lib_ranges_enumerate
|
||||||
|
#include <ranges>
|
||||||
|
namespace rv = std::views;
|
||||||
|
namespace rs = std::ranges;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// NOTE: missed, think big picture
|
||||||
|
// consider pos n - can either jump one and pay a[n], or skip and pay b[n] (static, must pay b[n])
|
||||||
|
// so - just do the best, lol
|
||||||
|
// then, brute-force consider any choices from 1-m
|
||||||
|
|
||||||
|
vec<u64> a(n), b(n);
|
||||||
|
for (auto& e : a)
|
||||||
|
cin >> e;
|
||||||
|
for (auto& e : b)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
i32 pos = n;
|
||||||
|
u64 acc = 0;
|
||||||
|
for (i32 i = n - 1; i >= m; --i) {
|
||||||
|
acc += min(a[i], b[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 ans = MAX<u64>;
|
||||||
|
u64 prefix = 0;
|
||||||
|
for (i32 i = m - 1; i >= 0; --i) {
|
||||||
|
ans = min(ans, acc + prefix + a[i]);
|
||||||
|
prefix += min(a[i], b[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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/935/debug_flags.txt
Normal file
14
codeforces/935/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
|
||||||
109
codeforces/935/e.cc
Normal file
109
codeforces/935/e.cc
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
#include <version>
|
||||||
|
#ifdef __cpp_lib_ranges_enumerate
|
||||||
|
#include <ranges>
|
||||||
|
namespace rv = std::views;
|
||||||
|
namespace rs = std::ranges;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 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, x, X;
|
||||||
|
cin >> n >> x;
|
||||||
|
vec<u32> a(n + 1);
|
||||||
|
for (u32 i = 1; i <= n; ++i) {
|
||||||
|
cin >> a[i];
|
||||||
|
if (a[i] == x)
|
||||||
|
X = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 l = 1, r = n + 1;
|
||||||
|
while (r - l > 1) {
|
||||||
|
auto m = (l + r) / 2;
|
||||||
|
if (a[m] <= x)
|
||||||
|
l = m;
|
||||||
|
else
|
||||||
|
r = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
println("1\n{} {}", X, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
125
codeforces/935/f.cc
Normal file
125
codeforces/935/f.cc
Normal file
|
|
@ -0,0 +1,125 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
#include <version>
|
||||||
|
#ifdef __cpp_lib_ranges_enumerate
|
||||||
|
#include <ranges>
|
||||||
|
namespace rv = std::views;
|
||||||
|
namespace rs = std::ranges;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
#include <ext/pb_ds/assoc_container.hpp>
|
||||||
|
#include <ext/pb_ds/tree_policy.hpp>
|
||||||
|
using namespace __gnu_pbds;
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
vec<u64> a(n);
|
||||||
|
for (auto& e : a)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
vec<u32> permutation(n);
|
||||||
|
for (auto& e : permutation)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
__gnu_pbds::tree<pair<u64, u32>, __gnu_pbds::null_type, less<pair<u64, u32>>,
|
||||||
|
__gnu_pbds::rb_tree_tag,
|
||||||
|
__gnu_pbds::tree_order_statistics_node_update>
|
||||||
|
tree;
|
||||||
|
for (u32 i = 0; i < n; ++i)
|
||||||
|
tree.insert({a[i], i});
|
||||||
|
|
||||||
|
u64 ans = 0, count = 0;
|
||||||
|
for (u32 i = 0; i < n; ++i) {
|
||||||
|
u32 k = min(i + 1, (u32)tree.size());
|
||||||
|
u64 score = (u64)k * tree.find_by_order(tree.size() - k)->first;
|
||||||
|
if (score > ans) {
|
||||||
|
ans = score;
|
||||||
|
count = k;
|
||||||
|
}
|
||||||
|
u32 j = permutation[i] - 1;
|
||||||
|
tree.erase({a[j], j});
|
||||||
|
}
|
||||||
|
|
||||||
|
println("{} {}", ans, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
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/935/io/a.in
Normal file
11
codeforces/935/io/a.in
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
10
|
||||||
|
1 2 3
|
||||||
|
1 4 1
|
||||||
|
1 4 2
|
||||||
|
1 1 1
|
||||||
|
1 3 2
|
||||||
|
19 7 18
|
||||||
|
0 0 0
|
||||||
|
7 0 0
|
||||||
|
0 24 0
|
||||||
|
1000000000 1000000000 1000000000
|
||||||
14
codeforces/935/io/a.out
Normal file
14
codeforces/935/io/a.out
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
3
|
||||||
|
-1
|
||||||
|
3
|
||||||
|
-1
|
||||||
|
3
|
||||||
|
28
|
||||||
|
0
|
||||||
|
7
|
||||||
|
8
|
||||||
|
1666666667
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.23827 ms
|
||||||
|
[debug]: false
|
||||||
7
codeforces/935/io/b.in
Normal file
7
codeforces/935/io/b.in
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
6
|
||||||
|
6 7 4
|
||||||
|
3 4 10
|
||||||
|
7 8 56
|
||||||
|
5 6 78123459896
|
||||||
|
1 1 1
|
||||||
|
1 1 1000000000000000000
|
||||||
10
codeforces/935/io/b.out
Normal file
10
codeforces/935/io/b.out
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
2
|
||||||
|
7
|
||||||
|
17
|
||||||
|
28645268630
|
||||||
|
4
|
||||||
|
2000000000000000002
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.33006 ms
|
||||||
|
[debug]: false
|
||||||
16
codeforces/935/io/c.in
Normal file
16
codeforces/935/io/c.in
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
7
|
||||||
|
3
|
||||||
|
101
|
||||||
|
6
|
||||||
|
010111
|
||||||
|
6
|
||||||
|
011001
|
||||||
|
3
|
||||||
|
000
|
||||||
|
3
|
||||||
|
110
|
||||||
|
3
|
||||||
|
001
|
||||||
|
4
|
||||||
|
1100
|
||||||
|
|
||||||
11
codeforces/935/io/c.out
Normal file
11
codeforces/935/io/c.out
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
2
|
||||||
|
3
|
||||||
|
2
|
||||||
|
3
|
||||||
|
0
|
||||||
|
1
|
||||||
|
0
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.31981 ms
|
||||||
|
[debug]: false
|
||||||
13
codeforces/935/io/d.in
Normal file
13
codeforces/935/io/d.in
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
4
|
||||||
|
4 2
|
||||||
|
7 3 6 9
|
||||||
|
4 3 8 5
|
||||||
|
6 2
|
||||||
|
6 9 7 1 8 3
|
||||||
|
5 8 8 1 4 1
|
||||||
|
7 7
|
||||||
|
7 2 9 2 6 5 9
|
||||||
|
9 1 10 7 1 4 9
|
||||||
|
2 1
|
||||||
|
2 3
|
||||||
|
1 1
|
||||||
8
codeforces/935/io/d.out
Normal file
8
codeforces/935/io/d.out
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
14
|
||||||
|
22
|
||||||
|
9
|
||||||
|
3
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.46668 ms
|
||||||
|
[debug]: false
|
||||||
11
codeforces/935/io/e.in
Normal file
11
codeforces/935/io/e.in
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
5
|
||||||
|
6 3
|
||||||
|
1 2 3 4 5 6
|
||||||
|
6 5
|
||||||
|
3 1 6 5 2 4
|
||||||
|
5 1
|
||||||
|
3 5 4 2 1
|
||||||
|
6 3
|
||||||
|
4 3 1 5 2 6
|
||||||
|
3 2
|
||||||
|
3 2 1
|
||||||
14
codeforces/935/io/e.out
Normal file
14
codeforces/935/io/e.out
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
1
|
||||||
|
3 3
|
||||||
|
1
|
||||||
|
4 6
|
||||||
|
1
|
||||||
|
5 1
|
||||||
|
1
|
||||||
|
2 3
|
||||||
|
1
|
||||||
|
2 3
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.33626 ms
|
||||||
|
[debug]: false
|
||||||
19
codeforces/935/io/f.in
Normal file
19
codeforces/935/io/f.in
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
6
|
||||||
|
3
|
||||||
|
9 8 14
|
||||||
|
3 2 1
|
||||||
|
5
|
||||||
|
1 2 3 4 5
|
||||||
|
1 2 3 4 5
|
||||||
|
6
|
||||||
|
1 2 3 4 5 6
|
||||||
|
6 5 4 3 2 1
|
||||||
|
5
|
||||||
|
1 4 6 10 10
|
||||||
|
2 1 4 5 3
|
||||||
|
4
|
||||||
|
2 2 5 5
|
||||||
|
4 2 3 1
|
||||||
|
5
|
||||||
|
1 2 9 10 10
|
||||||
|
1 4 2 3 5
|
||||||
10
codeforces/935/io/f.out
Normal file
10
codeforces/935/io/f.out
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
16 2
|
||||||
|
9 3
|
||||||
|
8 2
|
||||||
|
20 2
|
||||||
|
5 1
|
||||||
|
20 2
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 2.29096 ms
|
||||||
|
[debug]: false
|
||||||
30
codeforces/935/makefile
Normal file
30
codeforces/935/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/935/scripts/debug.sh
Normal file
29
codeforces/935/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/935/scripts/run.sh
Normal file
29
codeforces/935/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/935/scripts/utils.sh
Normal file
61
codeforces/935/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