QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131468#6409. Classical Data Structure ProblemWilliamsWA 5ms4224kbC++143.6kb2023-07-27 11:02:062023-07-27 11:02:08

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-27 11:02:08]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:4224kb
  • [2023-07-27 11:02:06]
  • 提交

answer

#include <bits/stdc++.h>
#define for_(i,a,b) for (int i = (a); i < (b); i++)
#define rep_(i,a,b) for (int i = (a); i <= (b); i++)
#define per_(i,a,b) for (int i = (a); i >= (b); i--)
#define pii pair<int, int>
#define pll pair<ll, ll> 
#define fi first
#define se second
#define ll long long
#define all(v) v.begin(), v.end()
#define clr(x) memset(x, 0, sizeof(x))
#define ull unsigned long long
#define pb push_back
#define DEBUG(x) cerr << #x << '=' << x << endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"]=";rep_(_x,(L),(R))cerr<<a[_x]<<" "; cerr<<endl; 
	#ifdef LOCAL
#define line cout << "--------------------------------" << endl;
#define CE cout << endl;
#define CO cout << "OK" << endl;
#define D DEBUG
    #endif
#define endl '\n'
#define int ll
using namespace std;
mt19937 gen(114514);
const int maxn = 1e6 + 10;
const int mod = 1LL<<30;
int n, m;
struct node {
	int val, sz, fix, a, b, K, B;
	node *ls, *rs;
	node(void){
	}
	node(int _val, node *emp, int _K, int _B) : ls(emp), rs(emp), val(_val), sz(1), fix(gen()), K(_K), B(_B), a(_K), b(_B){}
}*rt, *emp, pool[maxn], *curpool = pool;
node* newnode(int x, int K, int B) {
	node *u = ++curpool;
	*u = node(x, emp, K, B);
	return u;
}
void pushup(node *u) {
	u -> sz = u -> ls -> sz + u -> rs -> sz + 1;
	u -> a = u -> ls -> a + u -> rs -> a + u -> K;
	u -> b = u -> ls -> b + u -> rs -> b + u -> B;
	return;
}
void merge(node *&u, node *l, node *r) {
	if (l == emp) { u = r; return;}
	if (r == emp) { u = l; return;}	
	if (l -> fix > r -> fix) {
		u = l, merge(u -> rs, l -> rs, r);
	} else {
		u = r, merge(u -> ls, l, r -> ls);
	}
	pushup(u);
}
void split_val(node* u, node *&l, node *&r, int x) {
	if (u == emp) {
		l = r = emp;
		return;
	}
	if (u -> val <= x) {
		l = u;
		split_val(u -> rs, l -> rs, r, x);
		pushup(l);
	}
	else {
		r = u;
		split_val(u -> ls, l, r -> ls, x);
		pushup(r);
	}
}
void split_sz(node *u, node *&l, node *&r, int x) {
	if (u == emp) {
		l = r = emp;
		return;
	}
	if (u -> ls -> sz + 1 <= x) {
		l = u;
		split_sz(u -> rs, l -> rs, r, x - u -> ls -> sz - 1);
		pushup(l);
	} 
	else {
		r = u;
		split_sz(u -> ls, l, r -> ls, x);
		pushup(r);
	} 
	
}
void insert(int x, int k, int b) {
	node *l, *r, *mid;
	split_val(rt, l, r, x - 1); // (p, 0) i (0, -pi)
//	line;
//	D(k); D(b);
//	line;
	node *u = newnode(x, k, b);
	merge(rt, l, u);
	merge(rt, rt, r);
}
void dfs(node *u, int cnt = 0) {
	cnt++;
	if (u == emp) return;
	dfs(u -> ls, cnt);
	cout << cnt << ':' << (u -> val) << ' ' << (u -> a) << ' ' << (u -> b) << ' ' << (u -> K) << ' ' << (u -> B) << endl;
	dfs(u -> rs, cnt);
}
int get(int x) {
	node *l, *r, *mid;
	split_val(rt, l, r, x);
	ll tmp = 0; tmp = (l -> a) * x % mod + (l -> b); tmp %= mod;
	merge(rt, l, r);
	return tmp;
}

signed main() {
	#ifdef LOCAL
		freopen("w.in", "r", stdin);
	#endif
	emp = pool;
	emp -> sz = 0; emp -> K = emp -> B = 0;
	emp -> a = emp -> b = 0;
	node *u = newnode(0, 0, 0); 
	rt = newnode(1<<30, 0, 0);  merge(rt, u, rt); 
	cin >> n >> m;
	int x = 0; m = 1ll<<m;
	rep_(i, 1, n) {
		int p, q; cin >> p >> q;
		p = (p + x) % m;
		q = (q + x) % m;
		if (p > q) swap(p, q);
//		D(p);
//		D(q);
		insert(p, i, -(p - 1) * i % mod);
		insert(q + 1, -i, ((p - 1) * i % mod + (q - p + 1) * i % mod) % mod);
	//		dfs(rt);
	//		line;		
	//		get(q);
	//		get(p - 1);
	//		cout << get(q) << endl;
	//		cout << get(p - 1) <<endl; 
		x += get(q) - get(p - 1);
		x %= mod;
//		D(x);
//		line;
	}
	x = (x % mod + mod) % mod;
	cout << x << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

1 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

1 2
3 1

output:

3

result:

ok 1 number(s): "3"

Test #4:

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

input:

1 5
31 15

output:

17

result:

ok 1 number(s): "17"

Test #5:

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

input:

1 20
366738 218765

output:

147974

result:

ok 1 number(s): "147974"

Test #6:

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

input:

1 30
86669484 41969116

output:

44700369

result:

ok 1 number(s): "44700369"

Test #7:

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

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

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

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

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

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

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:

191359793

result:

wrong answer 1st numbers differ - expected: '374742544', found: '191359793'