QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#421811#7108. Couleurucup-team3215AC ✓2144ms38120kbC++233.4kb2024-05-26 06:15:532024-05-26 06:15:53

Judging History

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

  • [2024-05-26 06:15:53]
  • 评测
  • 测评结果:AC
  • 用时:2144ms
  • 内存:38120kb
  • [2024-05-26 06:15:53]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct node {
    int l{-1}, r{-1};
    int sum{0};
};

vector<node> all;

int add() {
    all.emplace_back();
    return all.size() - 1;
}

int add(node a) {
    all.push_back(a);
    return all.size() - 1;
}

int build(int l, int r) {
    if (l + 1 == r) {
        return add();
    }
    int m = (r + l) / 2;
    int id = add();
    all[id].l = build(l, m);
    all[id].r = build(m, r);
    return id;
}

int upd(int v, int l, int r, int k, int x) {
    if (l + 1 == r) {
        int id = add(all[v]);
        all[id].sum += x;
        return id;
    }
    int m = (r + l) / 2;
    int id = add(all[v]);
    if (k < m) {
        all[id].l = upd(all[v].l, l, m, k, x);
    } else {
        all[id].r = upd(all[v].r, m, r, k, x);
    }
    all[id].sum = all[all[id].l].sum + all[all[id].r].sum;
    return id;
}

int get(int v1, int v2, int l, int r, int lq, int rq) {
    if (l >= rq || lq >= r)return 0;
    if (l >= lq && r <= rq) { return all[v1].sum - all[v2].sum; }
    int m = (r + l) / 2;
    return get(all[v1].l, all[v2].l, l, m, lq, rq) + get(all[v1].r, all[v2].r, m, r, lq, rq);
}

using range = array<ll, 3>;

void solve() {
    all.clear();
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &i: a) {
        cin >> i;
        --i;
    }
    vector<int> versions(n + 1);
    versions.back() = build(0, n);
    ll score{0};
    for (int i = n - 1; ~i; --i) {
        versions[i] = upd(versions[i + 1], 0, n, a[i], 1);
        score += get(versions[i], versions[n], 0, n, 0, a[i]);
    }
    multiset<ll> best;
    set<range> s;
    s.insert({0, n, score});
    best.insert(score);
    for (ll i = 0; i < n; ++i) {
        if (i)cout << " ";
        ll last = *best.rbegin();
        cout << last;
        ll pos;
        cin >> pos;
        pos ^= last;
        --pos;
        auto it = s.lower_bound(range{pos, n + 1, n});
        assert(it != s.begin());
        --it;
        auto [l, r, score] = *it;
        s.erase(it);
        best.erase(best.find(score));
        if (pos - l < r - pos) {
            range left = {l, pos, 0};
            range right = {pos + 1, r, score};
            for (int j = l; j <= pos; ++j) {
                if (j != pos){
                    left[2] += (j - l) - get(versions[l], versions[j], 0, n, 0, a[j] + 1);
                }
                right[2] -= get(versions[pos], versions[r], 0, n, 0, a[j]);
            }
            right[2] -= left[2];
            s.insert(left);
            s.insert(right);
            best.insert(left[2]);
            best.insert(right[2]);
        } else {
            range left = {l, pos, score};
            range right = {pos + 1, r, 0};
            for (int j = pos; j < r; ++j) {
                if (j != pos) {
                    right[2] += (j - pos - 1) - get(versions[pos + 1], versions[j], 0, n, 0, a[j] + 1);
                }
                left[2] -= (pos + 1 - l) - get(versions[l], versions[pos + 1], 0, n, 0, a[j] + 1);
            }
            left[2] -= right[2];
            s.insert(left);
            s.insert(right);
            best.insert(left[2]);
            best.insert(right[2]);
        }
    }
}

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

    int t;
    cin >> t;
    for(int i = 0;i <t;++i){
        if(i)cout << "\n";solve();
    }
}

这程序好像有点Bug,我给组数据试试?

詳細信息

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: 0
Accepted
time: 2144ms
memory: 38120kb

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:

21 18 16 12 10 6 4 1 1 0
12 12 10 10 4 4 4 2 1 0
20 16 9 5 3 3 3 0 0 0
22 14 8 8 5 5 2 1 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
19 12 7 4 4 2 2 1 0 0
20 18 8 3 1 1 0 0 0 0
45 21 21 10 3 3 3 0 0 0
17 11 8 2 1 1 1 0 0 0
13 4 1 0 0 0 0 0 0 0
29 27 22 15 9 7 4 3 1 0
26 16 9 2 1 1 1 1 1 0
0 0 0 0 0 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed