codeforces rounds
This commit is contained in:
parent
6746faf742
commit
4ec6d74e65
88 changed files with 2039 additions and 13 deletions
20
codeforces/1049/2140a.cc
Normal file
20
codeforces/1049/2140a.cc
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void solve() {
|
||||
std::cout << "ho\n";
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int tc = 1;
|
||||
std::cin >> tc;
|
||||
|
||||
for (int t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
83
codeforces/1049/2140b.cc
Normal file
83
codeforces/1049/2140b.cc
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#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() {
|
||||
int x;
|
||||
cout << x << '\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;
|
||||
}
|
||||
// }}}
|
||||
4
codeforces/1049/io/2140a.expected
Normal file
4
codeforces/1049/io/2140a.expected
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
0
|
||||
1
|
||||
2
|
||||
1
|
||||
9
codeforces/1049/io/2140a.in
Normal file
9
codeforces/1049/io/2140a.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
4
|
||||
3
|
||||
001
|
||||
4
|
||||
0110
|
||||
6
|
||||
110100
|
||||
6
|
||||
101011
|
||||
9
codeforces/1049/io/2140a.out
Normal file
9
codeforces/1049/io/2140a.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
ho
|
||||
ho
|
||||
ho
|
||||
ho
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.76 ms
|
||||
[debug]: false
|
||||
[matches]: false
|
||||
6
codeforces/1049/io/2140b.expected
Normal file
6
codeforces/1049/io/2140b.expected
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
1
|
||||
12
|
||||
998
|
||||
7872
|
||||
8190
|
||||
174036
|
||||
7
codeforces/1049/io/2140b.in
Normal file
7
codeforces/1049/io/2140b.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
6
|
||||
8
|
||||
42
|
||||
1000
|
||||
66666
|
||||
106344
|
||||
9876543
|
||||
11
codeforces/1049/io/2140b.out
Normal file
11
codeforces/1049/io/2140b.out
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.49 ms
|
||||
[debug]: false
|
||||
[matches]: false
|
||||
93
codeforces/1050/2148a.cc
Normal file
93
codeforces/1050/2148a.cc
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#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 i16 = int16_t;
|
||||
using u16 = uint16_t;
|
||||
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() {
|
||||
u16 n, x;
|
||||
cin >> x >> n;
|
||||
|
||||
if (n & 1) {
|
||||
cout << x;
|
||||
} else {
|
||||
cout << 0;
|
||||
}
|
||||
|
||||
cout << '\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;
|
||||
}
|
||||
// }}}
|
||||
94
codeforces/1050/2148b.cc
Normal file
94
codeforces/1050/2148b.cc
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#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 i16 = int16_t;
|
||||
using u16 = uint16_t;
|
||||
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;
|
||||
u64 x, y;
|
||||
cin >> n >> m >> x >> y;
|
||||
|
||||
vec<u32> horiz(n), vert(m);
|
||||
for (auto &e : horiz)
|
||||
cin >> e;
|
||||
for (auto &e : vert)
|
||||
cin >> e;
|
||||
|
||||
println("{}", n + m);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
109
codeforces/1050/2148c.cc
Normal file
109
codeforces/1050/2148c.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 i16 = int16_t;
|
||||
using u16 = uint16_t;
|
||||
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;
|
||||
|
||||
u32 a, b;
|
||||
|
||||
u16 side = 0;
|
||||
u32 t = 0;
|
||||
u32 ans = 0;
|
||||
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> a >> b;
|
||||
|
||||
// at time a, must be at side b; was on side side @ time t
|
||||
|
||||
u32 diff = a - t;
|
||||
ans += diff;
|
||||
if (diff & 1 && b == side || !(diff & 1) && b != side) {
|
||||
--ans;
|
||||
}
|
||||
t = a;
|
||||
side = b;
|
||||
}
|
||||
|
||||
ans += m - t;
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
109
codeforces/1050/2148d.cc
Normal file
109
codeforces/1050/2148d.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 i16 = int16_t;
|
||||
using u16 = uint16_t;
|
||||
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, a;
|
||||
cin >> n;
|
||||
|
||||
vec<u32> odd;
|
||||
u64 even_total = 0, ans = 0;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> a;
|
||||
|
||||
if (a & 1) {
|
||||
odd.push_back(a);
|
||||
} else {
|
||||
even_total += a;
|
||||
}
|
||||
}
|
||||
|
||||
sort(rall(odd));
|
||||
|
||||
for (u32 i = 0; i < (odd.size() + 1) / 2; ++i) {
|
||||
ans += odd[i];
|
||||
}
|
||||
|
||||
if (ans > 0) {
|
||||
ans += even_total;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
112
codeforces/1050/2148e.cc
Normal file
112
codeforces/1050/2148e.cc
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#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 i16 = int16_t;
|
||||
using u16 = uint16_t;
|
||||
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, k;
|
||||
cin >> n >> k;
|
||||
vec<u32> a(n);
|
||||
vec<u32> F(n + 1, 0);
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
cin >> a[i];
|
||||
++F[a[i]];
|
||||
}
|
||||
|
||||
for (auto &f : F) {
|
||||
if (f % k) {
|
||||
println("0");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
u64 ans = 0;
|
||||
map<u32, u32> f;
|
||||
|
||||
for (u32 l = 0, r = 0; r < n; ++r) {
|
||||
++f[a[r]];
|
||||
while (f[a[r]] * k > F[a[r]]) {
|
||||
--f[a[l]];
|
||||
++l;
|
||||
}
|
||||
ans += r - l + 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
5
codeforces/1050/io/2148a.1.cpin
Normal file
5
codeforces/1050/io/2148a.1.cpin
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
1 4
|
||||
2 5
|
||||
3 6
|
||||
4 7
|
||||
4
codeforces/1050/io/2148a.1.cpout
Normal file
4
codeforces/1050/io/2148a.1.cpout
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
0
|
||||
2
|
||||
0
|
||||
4
|
||||
5
codeforces/1050/io/2148a.cpin
Normal file
5
codeforces/1050/io/2148a.cpin
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
1 4
|
||||
2 5
|
||||
3 6
|
||||
4 7
|
||||
9
codeforces/1050/io/2148a.cpout
Normal file
9
codeforces/1050/io/2148a.cpout
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
0
|
||||
2
|
||||
0
|
||||
4
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.70 ms
|
||||
[debug]: false
|
||||
[ok]: true
|
||||
4
codeforces/1050/io/2148a.expected
Normal file
4
codeforces/1050/io/2148a.expected
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
0
|
||||
2
|
||||
0
|
||||
4
|
||||
7
codeforces/1050/io/2148b.1.cpin
Normal file
7
codeforces/1050/io/2148b.1.cpin
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2
|
||||
1 1 2 2
|
||||
1
|
||||
1
|
||||
2 1 100000 100000
|
||||
42 58
|
||||
32
|
||||
2
codeforces/1050/io/2148b.1.cpout
Normal file
2
codeforces/1050/io/2148b.1.cpout
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
2
|
||||
3
|
||||
7
codeforces/1050/io/2148b.cpin
Normal file
7
codeforces/1050/io/2148b.cpin
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2
|
||||
1 1 2 2
|
||||
1
|
||||
1
|
||||
2 1 100000 100000
|
||||
42 58
|
||||
32
|
||||
7
codeforces/1050/io/2148b.cpout
Normal file
7
codeforces/1050/io/2148b.cpout
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2
|
||||
3
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.45 ms
|
||||
[debug]: false
|
||||
[ok]: true
|
||||
2
codeforces/1050/io/2148b.expected
Normal file
2
codeforces/1050/io/2148b.expected
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
2
|
||||
3
|
||||
12
codeforces/1050/io/2148c.1.cpin
Normal file
12
codeforces/1050/io/2148c.1.cpin
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
3
|
||||
2 4
|
||||
2 1
|
||||
4 0
|
||||
2 7
|
||||
1 1
|
||||
4 0
|
||||
4 9
|
||||
1 0
|
||||
2 0
|
||||
6 1
|
||||
9 0
|
||||
3
codeforces/1050/io/2148c.1.cpout
Normal file
3
codeforces/1050/io/2148c.1.cpout
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
2
|
||||
7
|
||||
6
|
||||
12
codeforces/1050/io/2148c.cpin
Normal file
12
codeforces/1050/io/2148c.cpin
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
3
|
||||
2 4
|
||||
2 1
|
||||
4 0
|
||||
2 7
|
||||
1 1
|
||||
4 0
|
||||
4 9
|
||||
1 0
|
||||
2 0
|
||||
6 1
|
||||
9 0
|
||||
8
codeforces/1050/io/2148c.cpout
Normal file
8
codeforces/1050/io/2148c.cpout
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
2
|
||||
7
|
||||
6
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.88 ms
|
||||
[debug]: false
|
||||
[ok]: true
|
||||
3
codeforces/1050/io/2148c.expected
Normal file
3
codeforces/1050/io/2148c.expected
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
2
|
||||
7
|
||||
6
|
||||
7
codeforces/1050/io/2148d.1.cpin
Normal file
7
codeforces/1050/io/2148d.1.cpin
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
3
|
||||
3
|
||||
2 4 6
|
||||
4
|
||||
4 2 1 6
|
||||
4
|
||||
1000000000 999999999 1000000000 999999999
|
||||
3
codeforces/1050/io/2148d.1.cpout
Normal file
3
codeforces/1050/io/2148d.1.cpout
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
0
|
||||
13
|
||||
2999999999
|
||||
7
codeforces/1050/io/2148d.cpin
Normal file
7
codeforces/1050/io/2148d.cpin
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
3
|
||||
3
|
||||
2 4 6
|
||||
4
|
||||
4 2 1 6
|
||||
4
|
||||
1000000000 999999999 1000000000 999999999
|
||||
8
codeforces/1050/io/2148d.cpout
Normal file
8
codeforces/1050/io/2148d.cpout
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
0
|
||||
13
|
||||
2999999999
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.53 ms
|
||||
[debug]: false
|
||||
[ok]: true
|
||||
3
codeforces/1050/io/2148d.expected
Normal file
3
codeforces/1050/io/2148d.expected
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
0
|
||||
13
|
||||
2999999999
|
||||
9
codeforces/1050/io/2148e.1.cpin
Normal file
9
codeforces/1050/io/2148e.1.cpin
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
4
|
||||
3 2
|
||||
1 1 1
|
||||
4 2
|
||||
1 2 1 2
|
||||
8 2
|
||||
3 3 3 3 2 2 2 2
|
||||
6 3
|
||||
1 1 1 1 1 1
|
||||
4
codeforces/1050/io/2148e.1.cpout
Normal file
4
codeforces/1050/io/2148e.1.cpout
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
0
|
||||
7
|
||||
18
|
||||
11
|
||||
9
codeforces/1050/io/2148e.cpin
Normal file
9
codeforces/1050/io/2148e.cpin
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
4
|
||||
3 2
|
||||
1 1 1
|
||||
4 2
|
||||
1 2 1 2
|
||||
8 2
|
||||
3 3 3 3 2 2 2 2
|
||||
6 3
|
||||
1 1 1 1 1 1
|
||||
9
codeforces/1050/io/2148e.cpout
Normal file
9
codeforces/1050/io/2148e.cpout
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
0
|
||||
7
|
||||
18
|
||||
11
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.91 ms
|
||||
[debug]: false
|
||||
[ok]: true
|
||||
4
codeforces/1050/io/2148e.expected
Normal file
4
codeforces/1050/io/2148e.expected
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
0
|
||||
7
|
||||
18
|
||||
11
|
||||
86
codeforces/634/1335a.cc
Normal file
86
codeforces/634/1335a.cc
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#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;
|
||||
cin >> n;
|
||||
|
||||
u32 ans = (n + 1) / 2 - 1;
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
97
codeforces/634/1335b.cc
Normal file
97
codeforces/634/1335b.cc
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#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, a, b;
|
||||
cin >> n >> a >> b;
|
||||
|
||||
string ans(n, 'a');
|
||||
|
||||
char c = 'a';
|
||||
for (u32 i = a - 1, count = 0; count < b; ++count, --i) {
|
||||
ans[i] = c;
|
||||
++c;
|
||||
}
|
||||
|
||||
for (u32 i = a; i < n; ++i) {
|
||||
ans[i] = ans[i - 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;
|
||||
}
|
||||
// }}}
|
||||
117
codeforces/634/1335c.cc
Normal file
117
codeforces/634/1335c.cc
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#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;
|
||||
cin >> n;
|
||||
|
||||
vec<u32> a(n);
|
||||
map<u32, u32> f;
|
||||
for (auto &e : a) {
|
||||
cin >> e;
|
||||
++f[e];
|
||||
}
|
||||
|
||||
i32 l = 0, r = n / 2;
|
||||
|
||||
while (l <= r) {
|
||||
i32 m = l + (r - l) / 2;
|
||||
|
||||
bool ok = false;
|
||||
for (auto &[number, frequency] : f) {
|
||||
if (frequency >= m) {
|
||||
i32 rest = (i32)f.size() - (frequency == m);
|
||||
|
||||
if (rest >= m) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
r = m - 1;
|
||||
}
|
||||
}
|
||||
|
||||
println("{}", r);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
|
||||
88
codeforces/634/1335e1.cc
Normal file
88
codeforces/634/1335e1.cc
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
#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;
|
||||
cin >> n;
|
||||
vec<u32> a(n);
|
||||
for (auto &e : a)
|
||||
cin >> e;
|
||||
|
||||
cout << "hi\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;
|
||||
}
|
||||
// }}}
|
||||
123
codeforces/634/1335e2.cc
Normal file
123
codeforces/634/1335e2.cc
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
#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 u16 = uint16_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<u16> a(n);
|
||||
for (auto &e : a)
|
||||
cin >> e;
|
||||
|
||||
vec<vec<u32>> f(200 + 1);
|
||||
vec<vec<u32>> pref(200 + 1, vec<u32>(n + 1, 0));
|
||||
|
||||
u32 ans = 0;
|
||||
|
||||
for (u32 i = 1; i <= n; ++i) {
|
||||
f[a[i - 1]].push_back(i);
|
||||
|
||||
for (u32 x = 1; x <= 200; ++x) {
|
||||
pref[x][i] = pref[x][i - 1];
|
||||
}
|
||||
|
||||
ans = max(ans, ++pref[a[i - 1]][i]);
|
||||
}
|
||||
|
||||
for (u16 x = 1; x <= 200; ++x) {
|
||||
for (u32 A = 1; A <= f[x].size() / 2; ++A) {
|
||||
i32 l = f[x][A - 1] + 1;
|
||||
i32 r = f[x][f[x].size() - A] - 1;
|
||||
|
||||
if (l > r) {
|
||||
continue;
|
||||
}
|
||||
|
||||
u32 B = 0;
|
||||
for (u16 y = 1; y <= 200; ++y) {
|
||||
B = max(B, pref[y][r] - pref[y][l - 1]);
|
||||
}
|
||||
|
||||
ans = max(ans, 2 * A + 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;
|
||||
}
|
||||
// }}}
|
||||
91
codeforces/634/1335f.cc
Normal file
91
codeforces/634/1335f.cc
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#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() {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
1
codeforces/634/io/1068.1.cpin
Normal file
1
codeforces/634/io/1068.1.cpin
Normal file
|
|
@ -0,0 +1 @@
|
|||
3
|
||||
1
codeforces/634/io/1068.1.cpout
Normal file
1
codeforces/634/io/1068.1.cpout
Normal file
|
|
@ -0,0 +1 @@
|
|||
3 10 5 16 8 4 2 1
|
||||
1
codeforces/634/io/1068.cpin
Normal file
1
codeforces/634/io/1068.cpin
Normal file
|
|
@ -0,0 +1 @@
|
|||
3
|
||||
5
codeforces/634/io/1068.cpout
Normal file
5
codeforces/634/io/1068.cpout
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
3
|
||||
[code]: 0
|
||||
[time]: 2.44 ms
|
||||
[debug]: false
|
||||
[ok]: false
|
||||
1
codeforces/634/io/1068.expected
Normal file
1
codeforces/634/io/1068.expected
Normal file
|
|
@ -0,0 +1 @@
|
|||
3 10 5 16 8 4 2 1
|
||||
1
codeforces/634/io/1069.1.cpin
Normal file
1
codeforces/634/io/1069.1.cpin
Normal file
|
|
@ -0,0 +1 @@
|
|||
ATTCGGGA
|
||||
1
codeforces/634/io/1069.1.cpout
Normal file
1
codeforces/634/io/1069.1.cpout
Normal file
|
|
@ -0,0 +1 @@
|
|||
3
|
||||
1
codeforces/634/io/1069.cpin
Normal file
1
codeforces/634/io/1069.cpin
Normal file
|
|
@ -0,0 +1 @@
|
|||
ATTCGGGA
|
||||
4
codeforces/634/io/1069.cpout
Normal file
4
codeforces/634/io/1069.cpout
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
[code]: 124 (TIMEOUT)
|
||||
[time]: 2001.50 ms
|
||||
[debug]: false
|
||||
1
codeforces/634/io/1069.expected
Normal file
1
codeforces/634/io/1069.expected
Normal file
|
|
@ -0,0 +1 @@
|
|||
3
|
||||
13
codeforces/634/io/1335e1.1.cpin
Normal file
13
codeforces/634/io/1335e1.1.cpin
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
8
|
||||
1 1 2 2 3 2 1 1
|
||||
3
|
||||
1 3 3
|
||||
4
|
||||
1 10 10 1
|
||||
1
|
||||
26
|
||||
2
|
||||
2 1
|
||||
3
|
||||
1 1 1
|
||||
6
codeforces/634/io/1335e1.1.cpout
Normal file
6
codeforces/634/io/1335e1.1.cpout
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
7
|
||||
2
|
||||
4
|
||||
1
|
||||
1
|
||||
3
|
||||
13
codeforces/634/io/1335e1.cpin
Normal file
13
codeforces/634/io/1335e1.cpin
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
8
|
||||
1 1 2 2 3 2 1 1
|
||||
3
|
||||
1 3 3
|
||||
4
|
||||
1 10 10 1
|
||||
1
|
||||
26
|
||||
2
|
||||
2 1
|
||||
3
|
||||
1 1 1
|
||||
11
codeforces/634/io/1335e1.cpout
Normal file
11
codeforces/634/io/1335e1.cpout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
hi
|
||||
hi
|
||||
hi
|
||||
hi
|
||||
hi
|
||||
hi
|
||||
|
||||
[code]: 0
|
||||
[time]: 4.03 ms
|
||||
[debug]: false
|
||||
[ok]: false
|
||||
6
codeforces/634/io/1335e1.expected
Normal file
6
codeforces/634/io/1335e1.expected
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
7
|
||||
2
|
||||
4
|
||||
1
|
||||
1
|
||||
3
|
||||
13
codeforces/634/io/1335e2.1.cpin
Normal file
13
codeforces/634/io/1335e2.1.cpin
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
8
|
||||
1 1 2 2 3 2 1 1
|
||||
3
|
||||
1 3 3
|
||||
4
|
||||
1 10 10 1
|
||||
1
|
||||
26
|
||||
2
|
||||
2 1
|
||||
3
|
||||
1 1 1
|
||||
6
codeforces/634/io/1335e2.1.cpout
Normal file
6
codeforces/634/io/1335e2.1.cpout
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
7
|
||||
2
|
||||
4
|
||||
1
|
||||
1
|
||||
3
|
||||
13
codeforces/634/io/1335e2.cpin
Normal file
13
codeforces/634/io/1335e2.cpin
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
8
|
||||
1 1 2 2 3 2 1 1
|
||||
3
|
||||
1 3 3
|
||||
4
|
||||
1 10 10 1
|
||||
1
|
||||
26
|
||||
2
|
||||
2 1
|
||||
3
|
||||
1 1 1
|
||||
11
codeforces/634/io/1335e2.cpout
Normal file
11
codeforces/634/io/1335e2.cpout
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
7
|
||||
2
|
||||
4
|
||||
1
|
||||
1
|
||||
3
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.38 ms
|
||||
[debug]: false
|
||||
[ok]: true
|
||||
6
codeforces/634/io/1335e2.expected
Normal file
6
codeforces/634/io/1335e2.expected
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
7
|
||||
2
|
||||
4
|
||||
1
|
||||
1
|
||||
3
|
||||
17
codeforces/634/io/1933a.1.cpin
Normal file
17
codeforces/634/io/1933a.1.cpin
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
8
|
||||
3
|
||||
-2 3 -3
|
||||
1
|
||||
0
|
||||
2
|
||||
0 1
|
||||
1
|
||||
-99
|
||||
4
|
||||
10 -2 -3 7
|
||||
5
|
||||
-1 -2 -3 -4 -5
|
||||
6
|
||||
-41 22 -69 73 -15 -50
|
||||
12
|
||||
1 2 3 4 5 6 7 8 9 10 11 12
|
||||
8
codeforces/634/io/1933a.1.cpout
Normal file
8
codeforces/634/io/1933a.1.cpout
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
8
|
||||
0
|
||||
1
|
||||
99
|
||||
22
|
||||
15
|
||||
270
|
||||
78
|
||||
17
codeforces/634/io/1933a.cpin
Normal file
17
codeforces/634/io/1933a.cpin
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
8
|
||||
3
|
||||
-2 3 -3
|
||||
1
|
||||
0
|
||||
2
|
||||
0 1
|
||||
1
|
||||
-99
|
||||
4
|
||||
10 -2 -3 7
|
||||
5
|
||||
-1 -2 -3 -4 -5
|
||||
6
|
||||
-41 22 -69 73 -15 -50
|
||||
12
|
||||
1 2 3 4 5 6 7 8 9 10 11 12
|
||||
13
codeforces/634/io/1933a.cpout
Normal file
13
codeforces/634/io/1933a.cpout
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
-2 3 -3
|
||||
0
|
||||
0 1
|
||||
-99
|
||||
10 -2 -3 7
|
||||
-1 -2 -3 -4 -5
|
||||
-41 22 -69 73 -15 -50
|
||||
1 2 3 4 5 6 7 8 9 10 11 12
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.65 ms
|
||||
[debug]: false
|
||||
[matches]: false
|
||||
8
codeforces/634/io/1933a.expected
Normal file
8
codeforces/634/io/1933a.expected
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
8
|
||||
0
|
||||
1
|
||||
99
|
||||
22
|
||||
15
|
||||
270
|
||||
78
|
||||
1
codeforces/634/io/abc042a.1.cpin
Normal file
1
codeforces/634/io/abc042a.1.cpin
Normal file
|
|
@ -0,0 +1 @@
|
|||
5 5 7
|
||||
1
codeforces/634/io/abc042a.1.cpout
Normal file
1
codeforces/634/io/abc042a.1.cpout
Normal file
|
|
@ -0,0 +1 @@
|
|||
YES
|
||||
1
codeforces/634/io/abc042a.2.cpin
Normal file
1
codeforces/634/io/abc042a.2.cpin
Normal file
|
|
@ -0,0 +1 @@
|
|||
7 7 5
|
||||
1
codeforces/634/io/abc042a.2.cpout
Normal file
1
codeforces/634/io/abc042a.2.cpout
Normal file
|
|
@ -0,0 +1 @@
|
|||
NO
|
||||
3
codeforces/634/io/abc042a.cpin
Normal file
3
codeforces/634/io/abc042a.cpin
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
2
|
||||
5 5 7
|
||||
7 7 5
|
||||
7
codeforces/634/io/abc042a.cpout
Normal file
7
codeforces/634/io/abc042a.cpout
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
17
|
||||
19
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.68 ms
|
||||
[debug]: false
|
||||
[ok]: false
|
||||
2
codeforces/634/io/abc042a.expected
Normal file
2
codeforces/634/io/abc042a.expected
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
YES
|
||||
NO
|
||||
BIN
codeforces/920/f
Executable file
BIN
codeforces/920/f
Executable file
Binary file not shown.
112
codeforces/920/f.cc
Normal file
112
codeforces/920/f.cc
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
#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, q;
|
||||
cin >> n >> q;
|
||||
|
||||
vec<i64> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
u32 block_size = sqrt(n);
|
||||
|
||||
u32 s, d, k;
|
||||
for (u32 i = 0; i < q; ++i) {
|
||||
cin >> s >> d >> k;
|
||||
|
||||
i64 ans = 0;
|
||||
u32 index = s;
|
||||
for (i64 i = 1; i <= k; ++i, index += d) {
|
||||
ans += i * a[index - 1];
|
||||
}
|
||||
|
||||
cout << ans << " \n"[i == q - 1];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
5
codeforces/920/io/f.expected
Normal file
5
codeforces/920/io/f.expected
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
5 1 3
|
||||
-600000000
|
||||
22 12 55
|
||||
600000000
|
||||
171 42 118 66 -108 23 2
|
||||
26
codeforces/920/io/f.in
Normal file
26
codeforces/920/io/f.in
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
5
|
||||
3 3
|
||||
1 1 2
|
||||
1 2 2
|
||||
2 2 1
|
||||
1 1 2
|
||||
3 1
|
||||
-100000000 -100000000 -100000000
|
||||
1 1 3
|
||||
5 3
|
||||
1 2 3 4 5
|
||||
1 2 3
|
||||
2 3 2
|
||||
1 1 5
|
||||
3 1
|
||||
100000000 100000000 100000000
|
||||
1 1 3
|
||||
7 7
|
||||
34 87 5 42 -44 66 -32
|
||||
2 2 2
|
||||
4 3 1
|
||||
1 3 2
|
||||
6 2 1
|
||||
5 2 2
|
||||
2 5 2
|
||||
6 1 2
|
||||
10
codeforces/920/io/f.out
Normal file
10
codeforces/920/io/f.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
5 1 3
|
||||
-600000000
|
||||
22 12 55
|
||||
600000000
|
||||
171 42 118 66 -108 23 2
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.93 ms
|
||||
[debug]: false
|
||||
[matches]: true
|
||||
91
codeforces/920/solution.cc
Normal file
91
codeforces/920/solution.cc
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#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() {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
148
codeforces/962/f.cc
Normal file
148
codeforces/962/f.cc
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
#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() {
|
||||
i64 n, k;
|
||||
cin >> n >> k;
|
||||
vector<i64> a(n), b(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
for (auto& e : b)
|
||||
cin >> e;
|
||||
|
||||
i64 l = 0, r = *max_element(a.begin(), a.end());
|
||||
vector<i64> last_a(n);
|
||||
i64 ans = 0, operations = 0;
|
||||
|
||||
while (l <= r) {
|
||||
i64 m = l + (r - l) / 2, s = 0, o = 0;
|
||||
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
if (a[i] >= m) {
|
||||
i64 O = (a[i] - m) / b[i] + 1;
|
||||
s += O * a[i] - b[i] * O * (O - 1) / 2;
|
||||
o += O;
|
||||
}
|
||||
}
|
||||
|
||||
if (o <= k) {
|
||||
ans = s;
|
||||
operations = o;
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
i64 O = (a[i] - m) / b[i] + 1;
|
||||
if (a[i] >= m) {
|
||||
last_a[i] = a[i] - O * b[i];
|
||||
}
|
||||
}
|
||||
r = m - 1;
|
||||
} else
|
||||
l = m + 1;
|
||||
}
|
||||
|
||||
auto brute_force = [&]() {
|
||||
set<pair<i64, i64>> tree;
|
||||
i64 ans = 0;
|
||||
for (i64 i = 0; i < n; ++i)
|
||||
if (last_a[i] > 0)
|
||||
tree.emplace(last_a[i], i);
|
||||
for (i64 _ = 0; _ < k && !tree.empty(); ++_) {
|
||||
auto it = prev(tree.end());
|
||||
auto [score, i] = *it;
|
||||
tree.erase(it);
|
||||
ans += score;
|
||||
if (score > b[i])
|
||||
tree.emplace(score - b[i], i);
|
||||
}
|
||||
return ans;
|
||||
};
|
||||
|
||||
k -= operations;
|
||||
if (k > 0)
|
||||
ans += brute_force();
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
5
codeforces/962/io/f.expected
Normal file
5
codeforces/962/io/f.expected
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
21
|
||||
349
|
||||
27
|
||||
500000500000
|
||||
47
|
||||
17
codeforces/962/io/f.in
Normal file
17
codeforces/962/io/f.in
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
5
|
||||
3 4
|
||||
5 6 7
|
||||
2 3 4
|
||||
5 9
|
||||
32 52 68 64 14
|
||||
18 14 53 24 8
|
||||
5 1000
|
||||
1 2 3 4 5
|
||||
5 4 3 2 1
|
||||
1 1000000
|
||||
1000000
|
||||
1
|
||||
10 6
|
||||
3 3 5 10 6 8 6 8 7 7
|
||||
6 1 7 4 1 1 8 9 3 1
|
||||
|
||||
10
codeforces/962/io/f.out
Normal file
10
codeforces/962/io/f.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
21
|
||||
349
|
||||
27
|
||||
500000500000
|
||||
47
|
||||
|
||||
[code]: 0
|
||||
[time]: 2.82 ms
|
||||
[debug]: false
|
||||
[matches]: false
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
12
|
||||
6 5 2 2 5 3
|
||||
4 1 2 1 4 1
|
||||
1 4 1 3 1 1
|
||||
5 5 1 4 5 2
|
||||
4 4 1 1 4 4
|
||||
10 10 1 6 10 8
|
||||
10 10 2 6 10 7
|
||||
10 10 9 1 8 1
|
||||
10 10 8 1 10 2
|
||||
10 10 1 1 2 1
|
||||
10 10 1 3 4 1
|
||||
10 10 3 1 1 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue