QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#164624#7108. Couleurucup-team203AC ✓1699ms28604kbC++173.0kb2023-09-05 11:20:152023-09-05 11:20:15

Judging History

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

  • [2023-09-05 11:20:15]
  • 评测
  • 测评结果:AC
  • 用时:1699ms
  • 内存:28604kb
  • [2023-09-05 11:20:15]
  • 提交

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 it = val.lower_bound({x, 0});
        if ((it == val.end() || (it != val.end() && it->first.first > x)))
            it--;
        auto [t, sum] = *it;
        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();
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3520kb

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: 1699ms
memory: 28604kb

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