UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203456#3554. Asnow_trace1002619ms40320kbC++111.2kb2024-02-25 12:19:292024-02-25 13:28:00

answer

#include<bits/stdc++.h>
using namespace std;
struct node{
	int lazy=0;int l,r,num0,num1;
	void add(){
		lazy^=1,swap(num0,num1);
	}
}tree[2000005];int tot =0 ;
void push_down(int k){
	if(tree[k].lazy){
		tree[k<<1].add();tree[k<<1|1].add();tree[k].lazy = 0;
	}
}
void push_up(int k){
	tree[k].num0 = tree[k<<1].num0+tree[k<<1|1].num0+(tree[k<<1].num1 ==0 and tree[k<<1|1].num1 == 0);
	tree[k].num1 = tree[k<<1].num1+tree[k<<1|1].num1+(tree[k<<1].num0 ==0 and tree[k<<1|1].num0 == 0);
}void build(int l,int r,int k){
	tree[k].l = l,tree[k].r = r;++tot;
	if(l == r){
		tree[k].num0 = 1,tree[k].num1 =0 ;return;
	}int mid = l+r>>1;
	build(l,mid,k<<1),build(mid+1,r,k<<1|1);push_up(k);
}void upd(int l,int r,int k){
	int ll=  tree[k].l,rr = tree[k].r;
	if(ll>r or l>rr)return ;
	if(l<=ll and rr<=r){
		tree[k].add();return;
	}push_down(k);upd(l,r,k<<1),upd(l,r,k<<1|1);push_up(k);
}int n,q;
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> q;
	build(1,n,1);
//	cout << tot << endl;
//cout << tree[1].num0 << endl;
	while(q--){
		int l,r;cin >> l >> r;upd(l,r,1);
		cout << tot-tree[1].num0 << '\n';
	}
	return 0;
}/*
这题真牛。
*/

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 3ms
memory: 40320kb

input:

3518 3574
1583 2547
2169 2446
929 3386
424 3058
1324 1882
910 3249
415 900
62 192
798 2221
1494 1821...

output:

1939
1391
3565
3076
3000
4261
3330
3596
3416
3722
3369
3591
2123
3506
3602
4191
3231
2967
3549
3037
...

result:

ok 3574 numbers

Test #2:

score: 10
Accepted
time: 3ms
memory: 40320kb

input:

4320 3128
752 3594
901 1922
4031 4283
1191 2989
6 3522
2948 3970
2538 3477
1685 2170
32 260
2300 253...

output:

5696
3662
4174
3511
4895
6485
4786
4771
4322
3849
3845
6157
3491
4563
4486
3993
4279
4133
4358
4147
...

result:

ok 3128 numbers

Test #3:

score: 10
Accepted
time: 3ms
memory: 40316kb

input:

4974 3824
760 4907
768 2866
2207 3837
2629 2873
1423 1767
1157 1572
1865 2149
563 1518
3874 4044
102...

output:

8302
4115
3501
3048
3744
3986
4561
5379
5041
3938
4517
2956
2109
4089
2658
3298
3260
2754
5152
5415
...

result:

ok 3824 numbers

Test #4:

score: 10
Accepted
time: 7ms
memory: 40320kb

input:

4926 3730
2602 4091
1320 2793
17 712
1571 4403
3877 4145
4288 4877
2284 3823
2415 4696
2987 4441
212...

output:

2992
5176
6575
2937
3267
3987
6300
3409
5429
4974
5212
5316
4965
5190
5684
6114
3829
4636
4194
3905
...

result:

ok 3730 numbers

Test #5:

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

input:

3187 4039
789 792
2497 2909
2178 2428
871 1830
30 1679
482 628
2389 2992
107 1180
116 3161
2025 2123...

output:

19
854
1363
3291
3338
3050
2457
2169
4348
4157
3821
3197
2856
3543
3382
3099
3025
3056
3359
3388
330...

result:

ok 4039 numbers

Test #6:

score: 10
Accepted
time: 389ms
memory: 40316kb

input:

498120 466300
147968 147968
397555 397555
46672 46672
189382 189382
396447 396447
262354 262354
1453...

output:

20
39
57
74
88
106
120
137
151
167
182
199
216
231
247
262
277
293
307
323
338
353
367
383
396
412
4...

result:

ok 466300 numbers

Test #7:

score: 10
Accepted
time: 395ms
memory: 40316kb

input:

453080 495815
117597 117597
147384 147384
323399 323399
250557 250557
351263 351263
81702 81702
1802...

output:

20
36
55
72
90
108
125
142
154
171
187
201
216
231
245
259
274
289
302
315
329
344
353
369
380
395
4...

result:

ok 495815 numbers

Test #8:

score: 10
Accepted
time: 696ms
memory: 40316kb

input:

496833 483174
250496 297573
74683 202076
275880 471935
82037 169344
144859 340702
161442 422741
6229...

output:

94172
348979
654328
479729
466454
348843
474892
519874
399089
328879
424953
384125
424572
342987
387...

result:

ok 483174 numbers

Test #9:

score: 10
Accepted
time: 537ms
memory: 40320kb

input:

448194 403135
82684 443461
26235 115906
195077 302474
176092 189983
3656 438870
386099 440867
13803 ...

output:

721573
768040
553258
525489
363440
464997
449858
326402
189013
265204
238438
629273
615263
383209
39...

result:

ok 403135 numbers

Test #10:

score: 10
Accepted
time: 586ms
memory: 40316kb

input:

475006 426104
86652 313013
311456 330183
131352 135536
237738 330903
60054 155047
73108 83759
154754...

output:

452742
483975
475618
298430
231589
210295
76495
422293
333599
388662
706978
465930
369656
604053
370...

result:

ok 426104 numbers

Extra Test:

score: 0
Extra Test Passed