QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560674#6409. Classical Data Structure ProblemMysterious_CatTL 500ms21140kbC++144.7kb2024-09-12 17:18:192024-09-12 17:18:19

Judging History

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

  • [2024-09-12 17:18:19]
  • 评测
  • 测评结果:TL
  • 用时:500ms
  • 内存:21140kb
  • [2024-09-12 17:18:19]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")

#include <bits/stdc++.h>
using namespace std;

const int M = 5e5 + 5;

int n, m, ans;

int rt, tot, fa[M], son[M][2], cnt[M], sz[M], val[M];
unsigned int a[M], b[M], A[M], B[M];

void clear(int x) {
    fa[x] = son[x][0] = son[x][1] = cnt[x] = sz[x] = val[x] = 0;
}

void pushup(int x) {
    sz[x] = sz[son[x][0]] + sz[son[x][1]] + cnt[x];
    a[x] = a[son[x][0]] + a[son[x][1]] + A[x];
    b[x] = b[son[x][0]] + b[son[x][1]] + B[x];
}

bool get(int x) {
    return x == son[fa[x]][1];
}

void rotate(int x) {
    int y = fa[x];
    int z = fa[y];
    bool c = get(x);
    son[y][c] = son[x][c ^ 1];
    if (son[x][c ^ 1]) {
        fa[son[x][c ^ 1]] = y;
    }
    son[x][c ^ 1] = y;
    fa[y] = x;
    fa[x] = z;
    if (z) {
        son[z][y == son[z][1]] = x;
    }
    pushup(y);
}

void splay(int x, int t) {
    for (int f = fa[x]; f != t; rotate(x), f = fa[x]) {
        if (fa[f] != t) {
            rotate(get(f) == get(x) ? f : x);
        }
    }
    if (t == 0) {
    	rt = x;
    }
    pushup(x);
}

void insert(int k, unsigned int v) {
    if (!rt) {
        val[++tot] = k;
        A[tot] = v;
        B[tot] += (unsigned)k * v;
        cnt[tot]++;
        rt = tot;
        pushup(rt);
        return;
    }
    int cur = rt, f = 0;
    while (1) {
        if (val[cur] == k) {
            cnt[cur]++;
            A[cur] += v;
            B[cur] += (unsigned)k * v;
            pushup(cur);
            pushup(f);
            splay(cur, 0);
            break;
        }
        f = cur;
        cur = son[cur][k > val[cur]];
        if (!cur) {
            val[++tot] = k;
            cnt[tot]++;
            A[tot] = v;
            B[tot] = (unsigned)k * v;
            fa[tot] = f;
            son[f][k > val[f]] = tot;
            pushup(tot);
            pushup(f);
            splay(tot, 0);
            break;
        }
    }
}

int find(int k) {
    int cur = rt;
    while (cur) {
        if (k == val[cur]) {
        	return cur;
        } else if (k < val[cur]) {
        	cur = son[cur][0];
        } else {
        	cur = son[cur][1];
        }
    }
    return cur;
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		int l, r;
		cin >> l >> r;
		l = (l + ans) & (1 << m) - 1;
		r = (r + ans) & (1 << m) - 1;
		if (l > r) {
			swap(l, r);
		}
		insert(l, i);
		if (r + 1 < 1 << m) {
			insert(r + 1, 0u - (unsigned)i);
		}
        int u = find(l), v = find(r + 1);
        splay(v, 0);
        splay(u, v);
        ans += (a[u] - a[son[u][0]]) * (unsigned)(r + 1) - (b[u] - b[son[u][0]]) + a[son[u][0]] * (unsigned)(r - l + 1);
	}
	cout << (ans & (1 << 30) - 1) << '\n';

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 11748kb

input:

1 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

1 2
3 1

output:

3

result:

ok 1 number(s): "3"

Test #4:

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

input:

1 5
31 15

output:

17

result:

ok 1 number(s): "17"

Test #5:

score: 0
Accepted
time: 2ms
memory: 11692kb

input:

1 20
366738 218765

output:

147974

result:

ok 1 number(s): "147974"

Test #6:

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

input:

1 30
86669484 41969116

output:

44700369

result:

ok 1 number(s): "44700369"

Test #7:

score: 0
Accepted
time: 2ms
memory: 9796kb

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: 0
Accepted
time: 2ms
memory: 11756kb

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:

20383734

result:

ok 1 number(s): "20383734"

Test #9:

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

input:

1000 1
0 1
1 0
1 0
1 0
1 0
0 1
0 0
0 1
0 0
0 0
1 1
0 0
1 0
0 1
0 1
1 1
0 1
0 1
0 0
1 1
1 0
0 1
1 1
0 0
0 1
0 0
1 1
1 0
1 1
1 1
0 0
1 1
1 0
0 0
0 1
1 1
0 1
0 0
1 1
1 1
0 1
0 0
0 1
0 1
1 1
1 0
1 0
1 1
1 1
1 0
1 1
1 0
1 1
1 1
1 0
0 1
0 0
0 1
0 0
0 0
1 1
0 1
1 1
0 0
0 1
0 1
1 0
0 1
0 0
0 0
0 0
1 1
1 1
1...

output:

190098735

result:

ok 1 number(s): "190098735"

Test #10:

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

input:

1000 5
8 18
31 28
19 3
15 28
5 22
19 1
26 27
17 17
5 26
6 27
10 6
5 2
3 19
6 6
28 16
17 16
0 21
7 31
13 25
13 10
28 30
0 13
21 5
2 9
25 28
4 18
31 13
1 26
30 3
5 8
19 16
22 10
15 17
3 25
6 27
18 26
27 1
26 29
18 21
14 20
5 1
26 9
7 13
19 25
15 11
24 17
12 28
24 17
4 27
20 27
31 18
25 17
1 28
5 0
16 ...

output:

794181769

result:

ok 1 number(s): "794181769"

Test #11:

score: 0
Accepted
time: 2ms
memory: 11784kb

input:

1000 10
732 399
190 578
491 867
330 55
113 400
34 734
790 927
201 156
107 359
790 398
401 523
634 505
570 305
281 513
551 35
610 33
231 330
833 756
213 444
412 315
139 165
533 21
35 977
319 884
894 72
149 667
16 538
282 860
850 550
100 99
801 138
159 34
468 852
840 853
368 994
469 906
393 298
464 89...

output:

755182648

result:

ok 1 number(s): "755182648"

Test #12:

score: 0
Accepted
time: 2ms
memory: 11952kb

input:

5000 15
7705 10737
21186 31441
10307 825
19372 1969
32358 6343
22487 31897
12802 25210
17920 4297
5726 8409
28174 12489
16532 12646
9916 14917
19592 26927
23987 9279
26951 31081
3673 10505
20727 10730
28961 26581
11005 29624
13931 32180
29764 19108
23553 28977
30178 6537
25586 3041
15333 31927
4671 ...

output:

374742544

result:

ok 1 number(s): "374742544"

Test #13:

score: 0
Accepted
time: 10ms
memory: 12328kb

input:

10000 20
914013 637387
162942 785196
55799 893293
359726 714014
109456 559963
689320 161360
164737 25370
260018 436870
801394 34900
564741 620583
1008448 956143
788249 695007
633673 1020122
431990 397822
253241 746513
322933 927863
843120 378180
343689 583409
788822 249760
839003 753443
910418 20908...

output:

719391110

result:

ok 1 number(s): "719391110"

Test #14:

score: 0
Accepted
time: 167ms
memory: 15048kb

input:

100000 30
1063412225 224331901
116583527 514118426
121269548 678461017
856756753 250958443
1064104926 412721149
829078609 544244155
734000135 742933979
9127283 962205064
595091107 123655320
593251579 687018764
1052215261 661849950
297391487 243419322
105274358 526149321
1069300711 46673358
208918023...

output:

252791218

result:

ok 1 number(s): "252791218"

Test #15:

score: 0
Accepted
time: 500ms
memory: 21140kb

input:

200000 30
340892656 331749003
569148929 1001014926
169562315 65082998
783728999 371358574
1068579249 78668714
697845492 972638257
499257742 966955403
924540097 249425391
76210210 270676008
1055790206 117898225
186726707 639941146
774774929 469533012
608214477 15295274
30556605 466457599
892407954 78...

output:

220823398

result:

ok 1 number(s): "220823398"

Test #16:

score: -100
Time Limit Exceeded

input:

300000 30
692114910 439166105
1021714331 414169601
217855081 525446803
710701245 491758705
1073053571 818358104
566612376 327290534
264515348 117235003
766211086 610387541
631071137 417696697
444587009 622519510
394979978 618032341
178416548 695646703
37412772 578183052
65554323 886241839
502156061 ...

output:


result: