QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317333#6409. Classical Data Structure ProblemsupepapupuWA 1ms3736kbC++172.9kb2024-01-28 20:55:192024-01-28 20:55:19

Judging History

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

  • [2024-01-28 20:55:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3736kb
  • [2024-01-28 20:55:19]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
#define debug(x) cerr << #x << ": " << x << el
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 5e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;

struct Node {
    int lc, rc;
    int l, r;
    int rnd;
    int sz, v, s, add;
    void init(int _l, int _r, int _v) {
        lc = rc = 0, l = _l, r = _r, rnd = rand(), sz = r - l + 1, v = _v, s = v * sz;
    }
}tr[N * 3];
int idx;

void pushup(int u) {
    tr[u].s = tr[tr[u].lc].s + tr[tr[u].rc].s + tr[u].v * (tr[u].r - tr[u].l + 1);
    tr[u].sz = tr[tr[u].lc].sz + tr[tr[u].rc].sz + tr[u].r - tr[u].l + 1;
}

void pushdown(int u) {
    auto &p = tr[u], &lc = tr[tr[u].lc], &rc = tr[tr[u].rc];
    if (p.add) {
        lc.add += p.add, lc.v += p.add, lc.s += p.add * lc.sz;
        rc.add += p.add, rc.v += p.add, rc.s += p.add * rc.sz;
        p.add = 0;
    }
}

void split(int p, int k, int &x, int &y) {
    if (!p) x = y = 0;
    else {
        pushdown(p);
        if (tr[p].l <= k) {
            x = p;
            split(tr[p].rc, k, tr[p].rc, y);
        }
        else {
            y = p;
            split(tr[p].lc, k, x, tr[p].lc);
        }
        pushup(p);
    }
}

int merge(int p, int q) {
    if (!p || !q) return p + q;
    else if (tr[p].rnd > tr[q].rnd) {
        pushdown(p);
        tr[p].rc = merge(tr[p].rc, q);
        pushup(p);
        return p;
    }
    else {
        pushdown(q);
        tr[q].lc = merge(p, tr[q].lc);
        pushup(q);
        return q;
    }
}

void pushtag(int p, int add) {
    tr[p].v += add, tr[p].s += add * tr[p].sz, tr[p].add += add;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m; cin >> n >> m;
    int last = 0, v = (1 << m) - 1;
    tr[++idx].init(0, v, 0);
    int root = 1;
    for (int i = 1; i <= n; ++i) {
        int l, r; cin >> l >> r;
        l = l + last & v, r = r + last & v;
        if (l > r) swap(l, r);
        int x, y, z, a;
        split(root, l, y, z);
        int p = y; while (tr[p].rc) p = tr[p].rc;
        split(y, tr[p].l - 1, x, y);
        if (tr[y].l != l) {
            tr[++idx].init(l, tr[y].r, tr[y].v);
            tr[y].init(tr[y].l, l - 1, tr[y].v);
            x = merge(x, y);
            y = idx;
        }
        y = merge(y, z);
        if (r == v) {
            pushtag(y, i);
            last += tr[y].s;
            root = merge(x, y);
            continue;
        }
        split(y, r + 1, y, z);
        p = y; while (tr[p].rc) p = tr[p].rc;
        split(y, tr[p].l - 1, a, y);
        if (tr[y].l != r + 1) {
            tr[++idx].init(r + 1, tr[y].r, tr[y].v);
            tr[y].init(tr[y].l, r, tr[y].v);
            y = merge(a, y), z = merge(idx, z);
        }
        pushtag(y, i);
        last += tr[y].s;
        root = merge(merge(x, y), z);
    }
    cout << (last & (1 << 30) - 1) << el;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3728kb

input:

5 2
2 1
1 3
3 2
1 0
0 2

output:

87

result:

ok 1 number(s): "87"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3684kb

input:

1 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

1 2
3 1

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

1 5
31 15

output:

17

result:

ok 1 number(s): "17"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

1 20
366738 218765

output:

147974

result:

ok 1 number(s): "147974"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

1 30
86669484 41969116

output:

44700369

result:

ok 1 number(s): "44700369"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 3688kb

input:

10 5
20 31
2 2
14 18
13 25
26 4
22 9
15 9
19 16
15 27
9 20

output:

1663

result:

wrong answer 1st numbers differ - expected: '1414', found: '1663'