UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#202084#3520. Fire and Iceshr10014582ms92428kbC++112.3kb2024-02-11 12:36:022024-02-11 13:13:03

answer

#include <bits/stdc++.h>
#define lc pos<<1
#define rc pos<<1|1
#define mid ((l+r)>>1)
using namespace std;
using P=array<int,5>;
using ll=long long;
const int N=4e5+5,M=(1<<20)+5,mod=998244353;
int q,n,m,OP,st[18][N],a[N],b[N],sx[N],sy[N];
vector<P> p;
void init(int op){
	int sz=op?m:n;
	auto&v=op?b:a;
	for(int i=1;i<=sz;i++) st[0][i]=i;
	auto cmp=[&](int x,int y) {return v[x]<v[y]?x:y;};
	for(int i=1;1<<i<=sz;i++) for(int j=1;j+(1<<i)-1<=sz;j++) st[i][j]=cmp(st[i-1][j],st[i-1][j+(1<<(i-1))]);
	function<void(int,int)> add=[&](int l,int r)->void{
		if(l>r) return;
		int t=__lg(r-l+1),c=cmp(st[t][l],st[t][r-(1<<t)+1]);
		p.push_back({op,v[c],l,c,r});
		add(l,c-1);add(c+1,r);
	};
	add(1,sz);
}
ll k1[M],v1[M],k2[M],v2[M],f0[M],fx[M],fy[M],fxy[M];
inline void fix(ll&x) {if(x>=mod) x-=mod;}
void cov(int x,int k,int v,int op){
	if(op)
		fix(k2[x]+=k),fix(v2[x]+=v);
	else
		fix(f0[x]+=v*v2[x]%mod),
		fix(fx[x]+=k*v2[x]%mod),
		fix(fy[x]+=k2[x]*v%mod),
		fix(fxy[x]+=k*k2[x]%mod),
		fix(k1[x]+=k),fix(v1[x]+=v);
}
void pushdown(int pos){
	for(int so:{lc,rc}){
		cov(so,k1[pos],v1[pos],0);
		cov(so,k2[pos],v2[pos],1);
		fix(f0[so]+=f0[pos]);
		fix(fx[so]+=fx[pos]);
		fix(fy[so]+=fy[pos]);
		fix(fxy[so]+=fxy[pos]);
	}
	k1[pos]=k2[pos]=v1[pos]=v2[pos]=f0[pos]=fx[pos]=fy[pos]=fxy[pos]=0;
}
void upd(int l,int r,int pos,int L,int R,int k,int v,int op){
	if(L>R) return;
	auto&h=op?sy:sx;
	if(L<=h[l]&&h[r]<=R) return cov(pos,k,v,op);
	pushdown(pos);
	if(L<=h[mid]) upd(l,mid,lc,L,R,k,v,op);
	if(R>=h[mid+1]) upd(mid+1,r,rc,L,R,k,v,op);
}
void print(int l,int r,int pos){
	if(l==r){
		if(!OP&&l<q) return;
		if(l) cout<<(f0[pos]+fx[pos]*sx[l]+fy[pos]*sy[l]+fxy[pos]*sx[l]%mod*sy[l])%mod<<"\n";
		return;
	}
	pushdown(pos);
	print(l,mid,lc);print(mid+1,r,rc);
}
int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin>>q>>OP>>a[n=sx[0]=1]>>b[m=sy[0]=1];
	for(int i=1,op;i<=q;i++){
		cin>>op;
		if(op) cin>>b[++m];
		else cin>>a[++n];
		sx[i]=n;sy[i]=m;
	}
	init(0);init(1);
	sort(begin(p),end(p),[&](P x,P y){
		int vx=x[0]?-x[1]:x[1],vy=y[0]?-y[1]:y[1];
		if(vx==vy) return x[0]>y[0];
		return vx<vy;
	});
	for(auto&x:p)
		upd(0,q,1,x[3],x[4],x[3]-x[2]+1,(x[3]-x[2]+1)*(mod+1ll-x[3])%mod,x[0]),
		upd(0,q,1,x[4]+1,x[0]?m:n,0,(x[3]-x[2]+1ll)*(x[4]-x[3]+1)%mod,x[0]);
	print(0,q,1);
	return 0;
}

详细

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

Subtask #1:

score: 10
Accepted

Test #1:

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

input:

98 1
-8893 5507
1 7341
1 -8846
1 -2309
1 -3300
1 2086
0 1931
1 -5825
1 -5710
0 -788
1 1672
1 -7089
0...

output:

0
0
0
0
0
4
4
4
12
15
15
18
18
21
102
115
130
145
181
188
204
220
253
270
283
300
326
344
363
392
41...

result:

ok 98 numbers

Test #2:

score: 0
Accepted
time: 5ms
memory: 3384kb

input:

88 1
-7861 -3277
1 3558
0 -3041
1 -2192
0 -8296
0 -8549
1 4344
1 3331
0 2730
0 8173
1 2115
1 8320
0 ...

output:

0
1
1
1
1
2
4
14
39
55
80
83
88
110
168
200
229
229
233
267
288
375
391
473
523
551
645
736
772
886
...

result:

ok 88 numbers

Test #3:

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

input:

98 1
-29 -9
0 10
1 27
0 16
0 5
1 -21
1 21
0 -13
0 13
1 -25
1 0
0 -3
0 11
1 7
1 -4
0 -20
1 1
1 12
1 1...

output:

1
3
9
12
12
18
26
38
38
45
57
74
94
118
134
166
210
266
334
365
492
492
531
586
631
693
738
827
891
...

result:

ok 98 numbers

Subtask #2:

score: 10
Accepted

Test #4:

score: 10
Accepted
time: 2ms
memory: 3588kb

input:

998 1
215 -163
1 127
0 80
1 281
0 253
0 -28
0 -167
0 244
1 -272
1 71
0 269
0 115
0 195
1 -85
1 -34
0...

output:

3
5
12
24
36
41
52
52
63
82
99
123
147
187
237
237
266
287
374
412
465
539
553
572
766
876
1078
1232...

result:

ok 998 numbers

Test #5:

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

input:

998 1
1909 2306
1 2628
1 1053
1 -2489
0 -1936
1 1451
1 764
1 1162
1 288
1 1962
0 -1068
0 1941
1 -280...

output:

3
6
6
12
13
15
18
22
29
43
78
90
104
120
120
120
130
150
162
184
224
266
278
538
573
611
681
811
855...

result:

ok 998 numbers

Test #6:

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

input:

957 1
-29732 4526
1 -4208
0 14298
0 -27626
0 24336
1 -10280
1 13636
1 -12744
1 4100
0 -29322
1 -1952...

output:

0
3
3
6
12
20
30
42
42
49
77
77
80
98
124
128
154
184
254
295
340
389
434
678
759
1171
1179
1237
143...

result:

ok 957 numbers

Subtask #3:

score: 10
Accepted

Test #7:

score: 10
Accepted
time: 20ms
memory: 6024kb

input:

9998 1
2547 16452
0 4177
1 -387
0 -3242
0 4682
0 22364
1 -28322
1 13928
0 17857
0 -16924
0 25441
0 2...

output:

3
9
12
18
27
27
42
60
60
64
72
72
84
87
95
95
95
95
175
193
224
224
227
247
335
346
589
628
647
685
...

result:

ok 9998 numbers

Test #8:

score: 0
Accepted
time: 14ms
memory: 6028kb

input:

9998 1
229 1912
0 2514
0 2276
1 2831
1 2651
0 1553
1 676
1 1634
0 2451
1 103
1 2988
0 1842
1 1348
1 ...

output:

3
6
18
36
60
100
150
225
315
420
588
756
945
1155
1386
1848
2376
2970
3510
4095
5005
6006
7098
8190
...

result:

ok 9998 numbers

Test #9:

score: 0
Accepted
time: 18ms
memory: 6024kb

input:

9993 1
-25069 16168
0 22566
0 -1054
1 21976
1 28294
1 -28558
1 20894
1 2074
0 -20167
0 -26068
0 4443...

output:

1
3
9
21
21
24
30
43
48
62
65
70
89
94
134
156
184
229
278
300
377
460
594
634
634
779
907
907
1027
...

result:

ok 9993 numbers

Subtask #4:

score: 20
Accepted

Test #10:

score: 20
Accepted
time: 1417ms
memory: 92420kb

input:

399998 0
25881 -13672
1 -14025
0 -16182
1 -23140
1 21862
0 8936
1 18168
1 -20997
1 5796
0 1291
0 -16...

output:

615140815

result:

ok 1 number(s): "615140815"

Test #11:

score: 0
Accepted
time: 1457ms
memory: 92424kb

input:

399998 0
86386 -257505
0 270235
0 -253563
1 39880
0 157332
0 -10713
0 -279088
0 78889
1 239382
1 -11...

output:

483874022

result:

ok 1 number(s): "483874022"

Test #12:

score: 0
Accepted
time: 1437ms
memory: 92416kb

input:

399993 0
-946592 -2209872
0 -2448922
0 -2074552
1 -647455
0 2491470
0 -65776
1 -1236977
0 2683006
1 ...

output:

475504591

result:

ok 1 number(s): "475504591"

Subtask #5:

score: 20
Accepted

Test #13:

score: 20
Accepted
time: 1458ms
memory: 92424kb

input:

399998 1
170847520 -733230204
0 437049364
1 307907810
1 192475487
0 208194163
0 439190852
1 -3961554...

output:

0
3
9
18
30
36
36
39
56
64
64
64
92
112
121
141
143
162
186
186
264
312
364
442
500
575
659
691
696
...

result:

ok 399998 numbers

Test #14:

score: 0
Accepted
time: 1484ms
memory: 92424kb

input:

399993 1
644188428 971215643
0 972912015
0 -245037205
1 721267121
0 162702949
0 846528337
1 22818373...

output:

3
6
18
30
45
63
71
89
110
134
144
171
201
212
238
309
338
363
399
422
449
488
506
557
644
675
877
90...

result:

ok 399993 numbers

Subtask #6:

score: 30
Accepted

Test #15:

score: 30
Accepted
time: 1482ms
memory: 92428kb

input:

399993 1
-196331 -13389
1 184084
1 141712
0 127607
1 -125103
1 -83579
1 178000
1 118306
1 138807
1 -...

output:

0
0
6
10
15
21
28
36
45
55
73
101
118
141
154
173
276
306
542
621
887
904
922
1036
1222
1276
1543
15...

result:

ok 399993 numbers

Test #16:

score: 0
Accepted
time: 1430ms
memory: 92420kb

input:

399998 1
-61894 -495271
1 -693277
0 -238496
1 -728272
1 -514560
1 660191
0 -1144705
1 278476
0 -5875...

output:

0
0
0
0
3
3
9
10
26
33
33
33
39
81
98
108
129
151
173
201
217
246
366
577
591
893
908
939
948
1039
1...

result:

ok 399998 numbers

Test #17:

score: 0
Accepted
time: 1481ms
memory: 92416kb

input:

399998 1
69460 1564551
1 1065080
1 1263405
0 1548702
1 1237874
1 1752136
0 61349
0 1027888
0 299794
...

output:

3
6
18
30
45
90
150
225
315
420
588
756
1008
1296
1620
2025
2475
3025
3630
4290
5005
5775
6600
7480
...

result:

ok 399998 numbers

Test #18:

score: 0
Accepted
time: 1443ms
memory: 92424kb

input:

399998 1
-674207 -1021614
0 -790812
0 -747261
1 -1309571
1 -1622552
1 -707684
1 -1044094
0 -680452
0...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
3
3
3
3
6
6
6
6
6
6
6
6
...

result:

ok 399998 numbers

Test #19:

score: 0
Accepted
time: 1432ms
memory: 92424kb

input:

399993 1
-125772 56415
0 -107863
1 22954
1 -77695
0 118391
0 34524
1 166725
1 41418
1 1449
0 56146
1...

output:

0
0
0
6
12
25
34
46
75
86
112
124
147
154
185
221
232
298
313
383
416
474
649
902
1058
1073
1278
160...

result:

ok 399993 numbers

Extra Test:

score: 0
Extra Test Passed