QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573481#9313. Make MaxwinterlWA 0ms3660kbC++202.4kb2024-09-18 18:57:352024-09-18 18:57:42

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 18:57:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-09-18 18:57:35]
  • 提交

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;
}

详细

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'