cleanup
This commit is contained in:
parent
7b9271093d
commit
a624bf812d
12 changed files with 0 additions and 296 deletions
|
|
@ -1,51 +0,0 @@
|
|||
12 13 10 9 8 4 11 5 7 6 2 1 3
|
||||
l m r
|
||||
|
||||
index at 11
|
||||
|
||||
M = 7 < index, A[M] =11 > k=2, need one < 2
|
||||
|
||||
L = 8, R = 13 M = 10
|
||||
12 13 10 9 8 4 11 5 7 6 2 1 3
|
||||
l M r
|
||||
|
||||
M = 8 < index, A[M] = 6 > k = 2, need one < 2
|
||||
|
||||
L = 11, R = 13, M = 12,
|
||||
|
||||
M > index, a[M] < k -> need one > 2
|
||||
L = 11, R = 11 -> good
|
||||
|
||||
overall, needed 2 lt 2, 1 gt 2
|
||||
|
||||
12 13 10 9 8 4 1 5 7 6 2 1 3
|
||||
|
||||
there aren't 2 lt 2 -> no
|
||||
|
||||
1 2 3 4 5 6 7 8 9 10 11 12 13
|
||||
12 13 10 9 8 4 11 5 7 6 2 1 3
|
||||
1 13 2
|
||||
|
||||
M = 7, 1 lt (11 > 2, Left)
|
||||
M = 10, 2 lt (6 > 2, Right)
|
||||
L = 11, R = 13, M = 12, 1 gt
|
||||
|
||||
done
|
||||
|
||||
|
||||
7 4
|
||||
3 1 5 2 7 6 4
|
||||
3 4 2
|
||||
2 3 5
|
||||
1 5 6
|
||||
1 7 3
|
||||
|
||||
|
||||
|
||||
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
||||
14 1 3 15 4 5 6 16 7 8 9 10 11 12 13 2
|
||||
1 16 14
|
||||
|
||||
L = 1, R = 16, M = 8 -> 16, go left (no cost)
|
||||
L = 1, R = 7, M = 4 -> 15, left (no cost)
|
||||
L = 1, R = 3, M = 2 -> go left (1 gt)
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
# hello
|
||||
|
||||
|
||||
l, r <= 10^9
|
||||
|
||||
so ~ 10^9 candidates
|
||||
|
||||
minimize the digit xor
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
#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 a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
YES();
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
solve();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
|
|
@ -1 +0,0 @@
|
|||
5 5 7
|
||||
|
|
@ -1 +0,0 @@
|
|||
YES
|
||||
|
|
@ -1 +0,0 @@
|
|||
7 7 5
|
||||
|
|
@ -1 +0,0 @@
|
|||
NO
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
// {{{
|
||||
#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>
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::print(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void pr(std::format_string<Args...> fmt) {
|
||||
std::print(fmt);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void prln(std::format_string<Args...> fmt) {
|
||||
std::println(fmt);
|
||||
}
|
||||
|
||||
void prln() {
|
||||
std::println();
|
||||
}
|
||||
|
||||
void prln(auto const& t) {
|
||||
std::println("{}", t);
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
|
||||
#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 main() {
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
void solve() {
|
||||
u32 n;
|
||||
string s;
|
||||
cin >> n >> s;
|
||||
|
||||
// Function to calculate minimum ops for alternating even-length string
|
||||
auto calc_min_ops = [](const vec<u32>& even_count, const vec<u32>& odd_count,
|
||||
u32 even_positions, u32 odd_positions) -> u32 {
|
||||
// Find most frequent characters in each position type
|
||||
pai<u32, u32> max_even = {0, 0}; // (char, count)
|
||||
pai<u32, u32> second_max_even = {0, 0};
|
||||
pai<u32, u32> max_odd = {0, 0};
|
||||
pai<u32, u32> second_max_odd = {0, 0};
|
||||
|
||||
for (u32 c = 0; c < 26; ++c) {
|
||||
if (even_count[c] > max_even.second) {
|
||||
second_max_even = max_even;
|
||||
max_even = {c, even_count[c]};
|
||||
} else if (even_count[c] > second_max_even.second) {
|
||||
second_max_even = {c, even_count[c]};
|
||||
}
|
||||
|
||||
if (odd_count[c] > max_odd.second) {
|
||||
second_max_odd = max_odd;
|
||||
max_odd = {c, odd_count[c]};
|
||||
} else if (odd_count[c] > second_max_odd.second) {
|
||||
second_max_odd = {c, odd_count[c]};
|
||||
}
|
||||
}
|
||||
|
||||
u32 option1 =
|
||||
(even_positions - max_even.second) + (odd_positions - max_odd.second);
|
||||
u32 option2 = MAX<u32>;
|
||||
if (max_even.first != max_odd.first) {
|
||||
option2 = (even_positions - even_count[max_odd.first]) +
|
||||
(odd_positions - odd_count[max_even.first]);
|
||||
} else {
|
||||
// Try second-best for one position type
|
||||
u32 sub_option1 = (even_positions - second_max_even.second) +
|
||||
(odd_positions - max_odd.second);
|
||||
u32 sub_option2 = (even_positions - max_even.second) +
|
||||
(odd_positions - second_max_odd.second);
|
||||
option2 = min(sub_option1, sub_option2);
|
||||
}
|
||||
|
||||
return min(option1, option2);
|
||||
};
|
||||
|
||||
if (n % 2 == 0) {
|
||||
// Even length case
|
||||
vec<u32> even_count(26, 0);
|
||||
vec<u32> odd_count(26, 0);
|
||||
|
||||
for (u32 i = 0; i < n; ++i) {
|
||||
if (i % 2 == 0) {
|
||||
even_count[s[i] - 'a']++;
|
||||
} else {
|
||||
odd_count[s[i] - 'a']++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << calc_min_ops(even_count, odd_count, n / 2, n / 2) << '\n';
|
||||
} else {
|
||||
// O(n) - use suffix?
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue