QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#315502#6409. Classical Data Structure ProblemJacka1WA 1ms3624kbC++232.5kb2024-01-27 13:47:582024-01-27 13:47:59

Judging History

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

  • [2024-01-27 13:47:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3624kb
  • [2024-01-27 13:47:58]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 4100010;

using i64 = long long;

const int mod = 1 << 30;

struct Node{
    int l, r, key;
    unsigned add, sum, val, sz, self;
} tr[N];
int n, m;
int root, idx;
int p, q, s;

int new_node(unsigned val, unsigned self) {
    int u = ++idx; 
    tr[u].key = rand();
    tr[u].val = val;
    tr[u].self = self;
    tr[u].sum = val * self;
    return u;
}

void pushadd(int u, unsigned v) {
    tr[u].val += v;
    tr[u].add += v;
    tr[u].sum += v * tr[u].sz;    
}

void pushdown(int u) {
    if (tr[u].add) {
        pushadd(tr[u].l, tr[u].add);
        pushadd(tr[u].r, tr[u].add);
        tr[u].add = 0;
    }
}

void pushup(int u) {
    tr[u].sum = tr[tr[u].l].sum + tr[tr[u].r].sum + tr[u].self * tr[u].val;
    tr[u].sz = tr[tr[u].l].sz + tr[tr[u].r].sz + tr[u].self;
}

void split(int u, int k, int &x, int &y) {
    if (!u) return x = y = 0, void();
    pushdown(u);
    if (tr[tr[u].l].sz < k) {
        if (tr[tr[u].l].sz + tr[u].self >= k) {
            int lsz = k - tr[tr[u].l].sz, rsz = tr[u].self - lsz;
            if (rsz) {
                x = new_node(tr[u].val, lsz), tr[x].l = tr[u].l;
                y = new_node(tr[u].val, rsz), tr[y].r = tr[u].r;
            } else {
                x = u, y = tr[u].r;
                tr[x].r = 0;
            } 
            pushup(x), pushup(y);
            return;
        } else {
            x = u;
            split(tr[u].r, k - tr[tr[u].l].sz - tr[u].self, tr[u].r, y);
        }
    } else {
        y = u;
        split(tr[u].l, k, x, tr[u].l);
    }
    pushup(u);
}

int merge(int x, int y) {
    if (!x || !y) return x | y;    
    if (tr[x].key < tr[y].key) {
        pushdown(x);
        tr[x].r = merge(tr[x].r, y);
        return pushup(x), x;
    } else {
        pushdown(y);
        tr[y].l = merge(x, tr[y].l);
        return pushup(y), y;
    }
    assert(false);
    return 0;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    cin >> n >> m;
    int M = 1 << m;
    root = idx = 1;
    tr[1].self = M, pushup(1);
    unsigned x = 0;
    for (int i = 1; i <= n; i++) {
        int l, r;
        cin >> l >> r;
        (l += x) %= M, (r += x) %= M;
        ++l, ++r;
        if (l > r) swap(l, r);
        split(root, l - 1, p, q);
        split(q, r - l + 1, q, s);
        pushadd(q, i);
        (x += tr[q].sum) %= (1 << 30);
        root = merge(merge(p, q), s);
    }
    cout << x << '\n';
    return 0;
}

詳細信息

Test #1:

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

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: 3504kb

input:

1 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

1 2
3 1

output:

3

result:

ok 1 number(s): "3"

Test #4:

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

input:

1 5
31 15

output:

17

result:

ok 1 number(s): "17"

Test #5:

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

input:

1 20
366738 218765

output:

147974

result:

ok 1 number(s): "147974"

Test #6:

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

input:

1 30
86669484 41969116

output:

44700369

result:

ok 1 number(s): "44700369"

Test #7:

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

input:

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

output:

1414

result:

ok 1 number(s): "1414"

Test #8:

score: -100
Wrong Answer
time: 1ms
memory: 3612kb

input:

100 10
245 987
817 813
743 560
548 504
116 479
223 199
775 998
126 542
791 823
96 318
69 349
0 584
245 601
119 513
93 820
115 307
838 978
249 767
433 287
240 8
22 683
169 720
395 592
903 866
919 652
510 563
858 345
938 250
550 239
981 7
784 926
212 644
272 365
490 871
470 987
571 53
65 593
515 370
1...

output:

23456558

result:

wrong answer 1st numbers differ - expected: '20383734', found: '23456558'