QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#573481 | #9313. Make Max | winterl | WA | 0ms | 3660kb | C++20 | 2.4kb | 2024-09-18 18:57:35 | 2024-09-18 18:57:42 |
Judging History
answer
#include <bits/stdc++.h>
#pragma region printlns
namespace std {
#ifndef _MSC_VER
template <typename... Args>
void print(const std::string_view fmt, const Args &...args) {
std::cout << std::vformat(fmt, std::make_format_args(args...));
}
template <typename... Args>
void println(const std::string_view fmt, const Args &...args) {
std::cout << std::vformat(fmt, std::make_format_args(args...)) << '\n';
}
void print(const std::string_view s) { std::cout << s; }
void println(const std::string_view s) { std::cout << s << '\n'; }
#endif
void println() { std::cout.put('\n'); }
void close_sync() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
}
#pragma endregion
auto solve() {
std::int64_t n;
std::cin >> n;
std::vector<std::int64_t> arr(n);
for (auto &&i: arr)
std::cin >> i;
using tree_t = std::list<std::pair<std::int64_t, std::int64_t> >;
tree_t tree;
std::unordered_map<std::int64_t, std::vector<tree_t::iterator> > dict;
for (std::int64_t l = 0, r = 0; r < n; l = r) {
while (r < n and arr[l] == arr[r])
r++;
dict[arr[l]].emplace_back(tree.emplace(tree.end(), r - l, arr[l]));
}
int64_t answer = 0;
auto &&merge = [&](auto &&from, const auto &&to) {
auto &&[from_len, from_data] = *from;
auto &&[to_len, to_data] = *to;
to_len += from_len;
if(to_data != from_data) // 值不相同才统计答案
answer += from_len;
tree.erase(from);
};
for (auto &&iterators: dict | std::views::values) {
for(auto &&it : iterators) {
if(tree.size() == 1) {
std::println("{}", answer);
return;
}
if(it == tree.begin()) {
merge(it, std::next(it));
continue;
}
if(std::next(it) == tree.end()) {
merge(it, std::prev(it));
continue;
}
if(std::prev(it)->second < std::next(it)->second)
merge(it, std::prev(it));
else
merge(it, std::next(it));
}
}
}
auto main() -> signed {
std::close_sync();
std::int64_t t;
std::cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3660kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 4 3
result:
wrong answer 3rd numbers differ - expected: '3', found: '4'