QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#653298#6409. Classical Data Structure ProblemwangjunruiWA 2ms5736kbC++142.3kb2024-10-18 19:51:222024-10-18 19:51:28

Judging History

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

  • [2024-10-18 19:51:28]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5736kb
  • [2024-10-18 19:51:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
constexpr int N = 5e5 + 5;
constexpr int mod = (1 << 30);
typedef long long ll;
int n, m;
struct Tree
{
	int l, r;
	int pos;
	int c1, c2;
	ll sum1, sum2;
	unsigned key;
} tree[N * 2];
#define lc(rt) tree[rt].l
#define rc(rt) tree[rt].r
int root, cnt;
mt19937 rnd(114514);
inline void print(int rt)
{
	if (!rt)
		return;
	print(lc(rt));
	printf("%d %d %d\n", tree[rt].pos, tree[rt].c1, tree[rt].c2);
	print(rc(rt));
}
inline int newnode(int pos, int val)
{
	int rt = ++cnt;
	tree[rt].pos = pos;
	tree[rt].c1 = val;
	tree[rt].c2 = (ll)pos * val % mod;
	tree[rt].sum1 = tree[rt].c1;
	tree[rt].sum2 = tree[rt].c2;
	tree[rt].key = rnd();
	return rt;
}
inline void pushup(int rt)
{
	tree[rt].sum1 = (tree[lc(rt)].sum1 + tree[rc(rt)].sum1 + tree[rt].c1) % mod;
	tree[rt].sum2 = (tree[lc(rt)].sum2 + tree[rc(rt)].sum2 + tree[rt].c2) % mod;
}
inline int merge(int x, int y)
{
	if (!x || !y)
		return x | y;
	if (tree[x].key > tree[y].key)
	{
		rc(x) = merge(rc(x), y);
		pushup(x);
		return x;
	}
	else
	{
		lc(y) = merge(x, lc(y));
		pushup(y);
		return y;
	}
}
inline void split(int rt, int val, int &x, int &y)
{
	if (!rt)
		x = y = 0;
	else
	{
		if (tree[rt].pos <= val)
		{
			x = rt;
			split(rc(rt), val, rc(x), y);
			pushup(x);
		}
		else
		{
			y = rt;
			split(lc(rt), val, x, lc(y));
			pushup(y);
		}
	}
}
inline void update(int pos, int val)
{
	if (pos == (1 << m))
		return;
	int x, y;
	split(root, pos, x, y);
	root = merge(merge(x, newnode(pos, val)), y);
}
inline int query(int pos)
{
	int x, y;
	split(root, pos, x, y);
	int ans = ((ll)tree[x].sum1 * (pos + 1) - tree[x].sum2 + mod) % mod;
	root = merge(x, y);
	return ans;
}
inline void update(int l, int r, int v)
{
	update(l, v);
	update(r + 1, mod - v);
}
inline int query(int l, int r)
{
	int res = query(r);
	if (l > 0)
		(res = res - query(l - 1) + mod) % mod;
	return res;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	int x = 0;
	for (int i = 1; i <= n; ++i)
	{
		int p, q;
		cin >> p >> q;
		p = (p + x) % (1 << m);
		q = (q + x) % (1 << m);
		if (p > q)
			swap(p, q);
		update(p, q, i);
		(x += query(p, q)) %= mod;
	}
	cout << x << '\n';
	return 0;
}

詳細信息

Test #1:

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

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

input:

1 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

1 2
3 1

output:

3

result:

ok 1 number(s): "3"

Test #4:

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

input:

1 5
31 15

output:

17

result:

ok 1 number(s): "17"

Test #5:

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

input:

1 20
366738 218765

output:

147974

result:

ok 1 number(s): "147974"

Test #6:

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

input:

1 30
86669484 41969116

output:

44700369

result:

ok 1 number(s): "44700369"

Test #7:

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

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: 0ms
memory: 3756kb

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: 0ms
memory: 3684kb

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

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: -100
Wrong Answer
time: 2ms
memory: 5736kb

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:

272599363

result:

wrong answer 1st numbers differ - expected: '755182648', found: '272599363'