QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780114#7108. CouleurrgnerdplayerRE 0ms3628kbC++232.8kb2024-11-25 01:17:402024-11-25 01:17:40

Judging History

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

  • [2024-11-25 01:17:40]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3628kb
  • [2024-11-25 01:17:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int t;
    cin >> t;

    auto solve = [&]() {
        int n;
        cin >> n;

        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        vector<pair<int, int>> segs{{0, n - 1}};
        vector<int> id(n, 0);
        vector<i64> inv(1);
        multiset<i64> vals;
        vector<ordered_set<pair<int, int>>> s(1);

        for (int i = 0; i < n; i++) {
            inv[0] += s[0].size() - s[0].order_of_key(pair(a[i], n));
            s[0].insert(pair(a[i], i));
        }
        vals.emplace(inv[0]);

        i64 lst = 0;

        for (int rep = 0; rep < n; rep++) {
            cout << (lst = *vals.rbegin()) << " \n"[rep + 1 == n];
            i64 p;
            cin >> p;
            p ^= lst;
            assert(1 <= p && p <= n);
            p--;

            int cur = id[p];
            id[p] = -1;
            auto [l, r] = segs[cur];
            vals.extract(inv[cur]);
            int nxt = segs.size();
            inv.emplace_back();
            s.emplace_back();

            if (p - l < r - p) {
                segs[cur] = {p + 1, r};
                segs.emplace_back(p - 1, r);
                for (int i = l; i < p; i++) {
                    id[i] = nxt;
                }
                for (int i = l; i <= p; i++) {
                    s[cur].erase(pair(a[i], i));
                    inv[cur] -= s[cur].order_of_key(pair(a[i], -1));
                }
                for (int i = p - 1; i >= l; i--) {
                    inv[nxt] += s[nxt].order_of_key(pair(a[i], -1));
                    s[nxt].insert(pair(a[i], i));
                }
            } else {
                segs[cur] = {l, p - 1};
                segs.emplace_back(p + 1, r);
                for (int i = p + 1; i <= r; i++) {
                    id[i] = nxt;
                }
                for (int i = r; i >= p; i--) {
                    s[cur].erase(pair(a[i], i));
                    inv[cur] -= s[cur].size() - s[cur].order_of_key(pair(a[i], n));
                }
                for (int i = p + 1; i <= r; i++) {
                    inv[nxt] += s[nxt].size() - s[nxt].order_of_key(pair(a[i], n));
                    s[nxt].insert(pair(a[i], i));
                }
            }

            vals.insert(inv[cur]);
            vals.insert(inv[nxt]);

            assert(inv.size() == segs.size() && segs.size() == s.size() && vals.size() == s.size());
        }
    };
    
    while (t--) {
        solve();
    }
    
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0
20 11 7 2 0 0 0 0 0 0
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0

result:

ok 3 lines

Test #2:

score: -100
Runtime Error

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:


result: