feat(codeforces): 799
This commit is contained in:
parent
1a5e885c8f
commit
375a673932
52 changed files with 3233 additions and 0 deletions
9
codeforces/849/.clang-format
Normal file
9
codeforces/849/.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
|
||||
23
codeforces/849/.clangd
Normal file
23
codeforces/849/.clangd
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wshadow
|
||||
- -Wnon-virtual-dtor
|
||||
- -Wold-style-cast
|
||||
- -Wcast-align
|
||||
- -Wunused
|
||||
- -Woverloaded-virtual
|
||||
- -Wpedantic
|
||||
- -Wmisleading-indentation
|
||||
- -Wduplicated-cond
|
||||
- -Wduplicated-branches
|
||||
- -Wlogical-op
|
||||
- -Wnull-dereference
|
||||
- -Wuseless-cast
|
||||
- -Wformat=2
|
||||
- -Wformat-overflow
|
||||
- -Wformat-truncation
|
||||
- -Wdouble-promotion
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
91
codeforces/849/a.cc
Normal file
91
codeforces/849/a.cc
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#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;
|
||||
|
||||
template <typename T> [[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T> [[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#else
|
||||
#define dbgln(...)
|
||||
#define dbg(...)
|
||||
#endif
|
||||
|
||||
inline static void NO() { prln("NO"); }
|
||||
|
||||
inline static void YES() { prln("YES"); }
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T> using ve = std::vector<T>;
|
||||
template <typename T, size_t N> using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2> using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts> using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts> using dq = std::deque<Ts...>;
|
||||
template <typename... Ts> using qu = std::queue<Ts...>;
|
||||
template <typename... Ts> using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts> using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) { return std::lower_bound(args...); };
|
||||
auto ub = [](auto... args) { return std::upper_bound(args...); };
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
unordered_map<char, int> m;
|
||||
void solve() {
|
||||
char c;
|
||||
cin >> c;
|
||||
|
||||
if (m.find(c) == m.end()) {
|
||||
NO();
|
||||
} else {
|
||||
YES();
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
for (auto c : "codeforces") {
|
||||
++m[c];
|
||||
}
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/849/a.in
Normal file
11
codeforces/849/a.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
e
|
||||
f
|
||||
g
|
||||
h
|
||||
i
|
||||
j
|
||||
120
codeforces/849/b.cc
Normal file
120
codeforces/849/b.cc
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
#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;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#else
|
||||
#define dbgln(...)
|
||||
#define dbg(...)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
char c;
|
||||
int x = 0, y = 0;
|
||||
bool ans = false;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> c;
|
||||
if (c == 'L') {
|
||||
--x;
|
||||
} else if (c == 'R') {
|
||||
++x;
|
||||
} else if (c == 'U') {
|
||||
++y;
|
||||
} else {
|
||||
--y;
|
||||
}
|
||||
|
||||
if (x == 1 && y == 1) {
|
||||
ans |= 1;
|
||||
}
|
||||
}
|
||||
ans ? YES() : NO();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
16
codeforces/849/b.in
Normal file
16
codeforces/849/b.in
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
7
|
||||
7
|
||||
UUURDDL
|
||||
2
|
||||
UR
|
||||
8
|
||||
RRRUUDDD
|
||||
3
|
||||
LLL
|
||||
4
|
||||
DUUR
|
||||
5
|
||||
RUDLL
|
||||
11
|
||||
LLLLDDRUDRD
|
||||
|
||||
114
codeforces/849/c.cc
Normal file
114
codeforces/849/c.cc
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#else
|
||||
#define dbgln(...)
|
||||
#define dbg(...)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
string s;
|
||||
cin >> s;
|
||||
int l = 0, r = n - 1;
|
||||
int ans = 0;
|
||||
while (l < r) {
|
||||
if (((s[l] - '0') ^ (s[r] - '0')) == 1) {
|
||||
++ans;
|
||||
++l;
|
||||
--r;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
prln("{}", n - 2 * ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
19
codeforces/849/c.in
Normal file
19
codeforces/849/c.in
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
9
|
||||
3
|
||||
100
|
||||
4
|
||||
0111
|
||||
5
|
||||
10101
|
||||
6
|
||||
101010
|
||||
7
|
||||
1010110
|
||||
1
|
||||
1
|
||||
2
|
||||
10
|
||||
2
|
||||
11
|
||||
10
|
||||
1011011010
|
||||
21
codeforces/849/compile_flags.txt
Normal file
21
codeforces/849/compile_flags.txt
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wshadow
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wpedantic
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
-Wlogical-op
|
||||
-Wnull-dereference
|
||||
-Wuseless-cast
|
||||
-Wformat=2
|
||||
-Wformat-overflow
|
||||
-Wformat-truncation
|
||||
-Wdouble-promotion
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
120
codeforces/849/d.cc
Normal file
120
codeforces/849/d.cc
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
#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;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#else
|
||||
#define dbgln(...)
|
||||
#define dbg(...)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
string s;
|
||||
cin >> s;
|
||||
int L = 1, R = 0;
|
||||
unordered_map<char, int> fl, fr;
|
||||
++fl[s[0]];
|
||||
for (int i = n - 1; i >= 1; --i) {
|
||||
if (++fr[s[i]] == 1)
|
||||
++R;
|
||||
}
|
||||
int ans = 1;
|
||||
for (int i = 1; i < n; ++i) {
|
||||
ans = max(ans, L + R);
|
||||
if (++fl[s[i]] == 1) {
|
||||
++L;
|
||||
}
|
||||
if (--fr[s[i]] == 0) {
|
||||
--R;
|
||||
}
|
||||
}
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
12
codeforces/849/d.in
Normal file
12
codeforces/849/d.in
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
5
|
||||
2
|
||||
aa
|
||||
7
|
||||
abcabcd
|
||||
5
|
||||
aaaaa
|
||||
10
|
||||
paiumoment
|
||||
4
|
||||
aazz
|
||||
|
||||
119
codeforces/849/e.cc
Normal file
119
codeforces/849/e.cc
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
#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;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#else
|
||||
#define dbgln(...)
|
||||
#define dbg(...)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
// NOTE: missed adjacent - realy? bang head against wall
|
||||
int n;
|
||||
cin >> n;
|
||||
ve<int> a(n);
|
||||
ll ans = 0;
|
||||
int odds = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> a[i];
|
||||
ans += abs(a[i]);
|
||||
if (a[i] <= 0) {
|
||||
++odds;
|
||||
a[i] *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (odds % 2 == 0) {
|
||||
prln("{}", ans);
|
||||
} else {
|
||||
sort(all(a));
|
||||
prln("{}", ans - 2 * a[0]);
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/849/e.in
Normal file
11
codeforces/849/e.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
5
|
||||
3
|
||||
-1 -1 -1
|
||||
5
|
||||
1 5 -5 0 2
|
||||
3
|
||||
1 2 3
|
||||
6
|
||||
-1 10 9 8 7 6
|
||||
4
|
||||
-1 0 -1 0
|
||||
135
codeforces/849/f.cc
Normal file
135
codeforces/849/f.cc
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
#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;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#else
|
||||
#define dbgln(...)
|
||||
#define dbg(...)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n, q;
|
||||
cin >> n >> q;
|
||||
ve<ll> a(n), dsum(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> a[i];
|
||||
int x = a[i];
|
||||
while (x > 0) {
|
||||
dsum[i] += x % 10;
|
||||
x /= 10;
|
||||
}
|
||||
}
|
||||
char cmd;
|
||||
int l, r, x;
|
||||
set<pa<int, int>> s;
|
||||
while (q--) {
|
||||
cin >> cmd;
|
||||
if (cmd == '2') {
|
||||
cin >> x;
|
||||
// NOTE: struggled with bounds here
|
||||
auto it = s.lower_bound({x, 0});
|
||||
if (it != s.begin())
|
||||
--it;
|
||||
if (it != s.end() && it->first <= x && it->second >= x)
|
||||
prln("{}", dsum[x - 1]);
|
||||
else
|
||||
prln("{}", x, a[x - 1]);
|
||||
} else {
|
||||
cin >> l >> r;
|
||||
auto it = s.lower_bound({l, r});
|
||||
if (it != s.end() && r >= it->first) {
|
||||
l = min(l, it->first);
|
||||
r = max(r, it->second);
|
||||
s.erase(it);
|
||||
}
|
||||
s.emplace(l, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
19
codeforces/849/f.in
Normal file
19
codeforces/849/f.in
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
3
|
||||
5 8
|
||||
1 420 69 1434 2023
|
||||
1 2 3
|
||||
2 2
|
||||
2 3
|
||||
2 4
|
||||
1 2 5
|
||||
2 1
|
||||
2 3
|
||||
2 5
|
||||
2 3
|
||||
9999 1000
|
||||
1 1 2
|
||||
2 1
|
||||
2 2
|
||||
1 1
|
||||
1
|
||||
2 1
|
||||
119
codeforces/849/g.cc
Normal file
119
codeforces/849/g.cc
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
#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;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#else
|
||||
#define dbgln(...)
|
||||
#define dbg(...)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
ll c;
|
||||
cin >> n >> c;
|
||||
priority_queue<int> pq;
|
||||
int x;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> x;
|
||||
pq.push(-x - i - 1);
|
||||
}
|
||||
// NOTE lost focus, missed fact that portals cost differently
|
||||
|
||||
ll ans = 0;
|
||||
while (!pq.empty()) {
|
||||
auto z = -pq.top();
|
||||
if (z > c)
|
||||
break;
|
||||
pq.pop();
|
||||
c -= z;
|
||||
++ans;
|
||||
}
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
21
codeforces/849/g.in
Normal file
21
codeforces/849/g.in
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
10
|
||||
5 6
|
||||
1 1 1 1 1
|
||||
8 32
|
||||
100 52 13 6 9 4 100 35
|
||||
1 1
|
||||
5
|
||||
4 5
|
||||
4 3 2 1
|
||||
5 9
|
||||
2 3 1 4 1
|
||||
5 8
|
||||
2 3 1 4 1
|
||||
4 3
|
||||
2 3 4 1
|
||||
4 9
|
||||
5 4 3 3
|
||||
2 14
|
||||
7 5
|
||||
5 600000000
|
||||
500000000 400000000 300000000 200000000 100000000
|
||||
121
codeforces/849/h.cc
Normal file
121
codeforces/849/h.cc
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
#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;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#else
|
||||
#define dbgln(...)
|
||||
#define dbg(...)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
auto lb = [](auto... args) {
|
||||
return std::lower_bound(args...);
|
||||
};
|
||||
auto ub = [](auto... args) {
|
||||
return std::upper_bound(args...);
|
||||
};
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
ll c;
|
||||
cin >> n >> c;
|
||||
ve<ll> a(n);
|
||||
ve<pa<ll, ll>> best;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> a[i];
|
||||
best.eb(i + 1 + a[i], n + 1 - i + a[i]);
|
||||
}
|
||||
sort(all(best), [](auto const& x, auto const& y) {
|
||||
return x.ff > y.ff || x.ss > y.ss;
|
||||
});
|
||||
|
||||
ll ans = 0;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (min(best[i].ff, best[i].ss) > c) {
|
||||
break;
|
||||
}
|
||||
c -= min(best[i].ff, best[i].ss);
|
||||
++ans;
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
22
codeforces/849/h.in
Normal file
22
codeforces/849/h.in
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
10
|
||||
5 6
|
||||
1 1 1 1 1
|
||||
8 32
|
||||
100 52 13 6 9 4 100 35
|
||||
1 1
|
||||
5
|
||||
4 5
|
||||
4 3 2 1
|
||||
5 9
|
||||
2 3 1 4 1
|
||||
5 8
|
||||
2 3 1 4 1
|
||||
4 3
|
||||
2 3 4 1
|
||||
4 9
|
||||
5 4 3 3
|
||||
2 14
|
||||
7 5
|
||||
5 600000000
|
||||
500000000 400000000 300000000 200000000 100000000
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue