QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#164621#7108. Couleurucup-team203RE 0ms0kbC++172.9kb2023-09-05 11:16:472023-09-05 11:16:47

Judging History

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

  • [2023-09-05 11:16:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-09-05 11:16:47]
  • 提交

answer

#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
const int N = 100005;

int n, a[N], root[N], tot;
struct node
{
    int val, l, r;
} st[N << 5];
#define lc st[cur].l
#define rc st[cur].r
void insert(int &cur, int pre, int l, int r, int p)
{
    cur = ++tot;
    if (l == r)
    {
        st[cur].val = st[pre].val + 1;
        return;
    }
    int mid = l + r >> 1;
    if (p <= mid)
        insert(lc, st[pre].l, l, mid, p), rc = st[pre].r;
    else
        insert(rc, st[pre].r, mid + 1, r, p), lc = st[pre].l;
    st[cur].val = st[lc].val + st[rc].val;
}
int query(int cur, int pre, int l, int r, int a, int b)
{
    if (a > r || b < l || a > b || !cur)
        return 0;
    if (a <= l && r <= b)
        return st[cur].val - st[pre].val;
    int mid = l + r >> 1;
    return query(lc, st[pre].l, l, mid, a, b) + query(rc, st[pre].r, mid + 1, r, a, b);
}
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i], insert(root[i], root[i - 1], 1, n, a[i]);
    map<pair<int, int>, i64> val;
    multiset<i64> mx;
    i64 ans = 0, x;
    for (int i = 2; i <= n; i++)
        ans += query(root[i], root[0], 1, n, a[i] + 1, n);
    val[{1, n}] = ans;
    mx.insert(ans);
    cout << ans;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        x ^= ans;
        if (i == n)
            break;
        auto [t, sum] = *(--val.upper_bound({x, 0}));
        mx.erase(mx.find(sum));
        auto [l, r] = t;
        val.erase({l, r});
        sum -= query(root[x - 1], root[l - 1], 1, n, a[x] + 1, n) + query(root[r], root[x], 1, n, 1, a[x] - 1);
        if (x - l < r - x)
        {
            i64 sum1 = 0;
            for (int j = l; j < x; j++)
            {
                sum -= query(root[r], root[x], 1, n, 1, a[j] - 1);
                sum1 += query(root[j], root[l - 1], 1, n, a[j] + 1, n);
            }
            if (l < x)
                val[{l, x - 1}] = sum1, mx.insert(sum1);
            if (r > x)
                val[{x + 1, r}] = sum - sum1, mx.insert(sum - sum1);
        }
        else
        {
            i64 sum1 = 0;
            for (int j = x + 1; j <= r; j++)
            {
                sum -= query(root[x - 1], root[l - 1], 1, n, a[j] + 1, n);
                sum1 += query(root[j], root[x], 1, n, a[j] + 1, n);
            }
            if (l < x)
                val[{l, x - 1}] = sum - sum1, mx.insert(sum - sum1);
            if (r > x)
                val[{x + 1, r}] = sum1, mx.insert(sum1);
        }
        ans = *mx.rbegin();
        cout << ' ' << ans;
    }
    cout << '\n';

    for (int i = 1; i <= tot; i++)
        st[i] = {0, 0, 0};
    tot = 0;
    fill(root + 1, root + n + 1, 0);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

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:


result: