QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#311680#8133. When Anton Saw This Task He Reacted With 😩grass8cowAC ✓389ms40388kbC++172.7kb2024-01-22 17:14:452024-01-22 17:14:46

Judging History

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

  • [2024-01-22 17:14:46]
  • 评测
  • 测评结果:AC
  • 用时:389ms
  • 内存:40388kb
  • [2024-01-22 17:14:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,q,sz[201000],top[201000],ls[201000],rs[201000];
const int mod=998244353;
#define ll long long 
struct xl{ll x,y,z;}a[201000],od[200100];
xl operator * (const xl &a,const xl &b){
	return (xl){(a.y*b.z-a.z*b.y)%mod,(a.z*b.x-a.x*b.z)%mod,(a.x*b.y-a.y*b.x)%mod};
}
int son[201000];
char O[2];
void dfs(int x){
	if(ls[x]){
		dfs(ls[x]),dfs(rs[x]),sz[x]=sz[ls[x]]+sz[rs[x]]+1;
		son[x]=(sz[ls[x]]>sz[rs[x]])?ls[x]:rs[x];
		od[x]=od[ls[x]]*od[rs[x]];
	}
	else{od[x]=a[x];return;}
}
int db[200100],bel[201000],dfn[201000];
void dfs2(int x,int ff){
	top[x]=ff;bel[dfn[x]=++dfn[0]]=x;
	if(!son[x]){db[x]=x;return;}
	dfs2(son[x],ff),db[x]=db[son[x]];dfs2(son[x]^ls[x]^rs[x],son[x]^ls[x]^rs[x]);
}
struct qq{ll a[3][3];};
qq operator * (const qq &x,const qq &y){
	qq z;memset(z.a,0,sizeof(z.a));
	for(int k=0;k<3;k++)for(int i=0;i<3;i++)for(int j=0;j<3;j++)
	z.a[i][j]+=x.a[i][k]*y.a[k][j];
	for(int i=0;i<3;i++)for(int j=0;j<3;j++)z.a[i][j]%=mod;
	return z;
}
qq e[200100],I;
int fp[200100],ch[201000][2];
qq GT(int u){
	qq c;memset(c.a,0,sizeof(c.a));
	if(!son[u])c.a[0][0]=a[u].x,c.a[0][1]=a[u].y,c.a[0][2]=a[u].z;
	else{
		int X=ls[u]^rs[u]^son[u];
		if(X==ls[u]){
			c.a[2][0]=od[X].y,c.a[1][0]=-od[X].z;
			c.a[0][1]=od[X].z,c.a[2][1]=-od[X].x;
			c.a[1][2]=od[X].x,c.a[0][2]=-od[X].y;
		}
		else{
			c.a[2][0]=-od[X].y,c.a[1][0]=od[X].z;
			c.a[0][1]=-od[X].z,c.a[2][1]=od[X].x;
			c.a[1][2]=-od[X].x,c.a[0][2]=od[X].y;
		}
	}
	return c;
}
void up(int u){
	e[u]=I;
	if(ch[u][1])e[u]=e[ch[u][1]];
	e[u]=e[u]*GT(u);
	if(ch[u][0])e[u]=e[u]*e[ch[u][0]];
}
int su[200100],rt[201000];
int cdq(int l,int r){
	if(l>r)return 0;
	int xp=-1;
	for(int i=l;i<=r;i++)if((su[i]-su[l-1])*2>=su[r]-su[l-1]){xp=i;break;}
	int u=bel[xp];
	ch[u][0]=cdq(l,xp-1),ch[u][1]=cdq(xp+1,r);
	if(ch[u][1])fp[ch[u][1]]=u;
	if(ch[u][0])fp[ch[u][0]]=u;
	up(u);
	return u;
}
int fa[201000];
int main(){
	I.a[0][0]=I.a[1][1]=I.a[2][2]=1;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++){
		scanf("%s",O);
		if(O[0]=='x')scanf("%d%d",&ls[i],&rs[i]),fa[ls[i]]=fa[rs[i]]=i;
		else scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].z);
	}
	dfs(1),dfs2(1,1);
	for(int i=1;i<=n;i++)if(top[i]==i){
		su[dfn[i]-1]=0;
		for(int j=dfn[i];j<=dfn[db[i]];j++)su[j]=su[j-1]+(sz[bel[j]]-sz[son[bel[j]]]);
		rt[i]=cdq(dfn[i],dfn[db[i]]);
	}
	for(int i=1,x,x_,y_,z_;i<=q;i++){
		scanf("%d%d%d%d",&x,&x_,&y_,&z_);
		a[x]=(xl){x_,y_,z_};
		while(x){
			int u=x;up(u);
			while(u!=rt[top[x]])u=fp[u],up(u);
			od[top[x]]=(xl){e[u].a[0][0],e[u].a[0][1],e[u].a[0][2]};
			x=fa[top[x]];
		}
		printf("%d %d %d\n",od[1].x,od[1].y,od[1].z);
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 3
x 2 3
v 1 0 1
x 4 5
v 0 2 1
v 1 1 1
4 1 2 3
5 0 1 1
4 0 2 2

output:

-2 0 2
1 -2 -1
0 0 0

result:

ok 9 numbers

Test #2:

score: 0
Accepted
time: 375ms
memory: 38172kb

input:

199999 100000
x 137025 65661
v 572518668 158967010 74946561
x 129836 192657
x 141948 187810
v 574918069 328924434 141474729
x 143312 111002
x 52772 148497
v 922857701 690080961 651915759
v 656198340 28002884 129579416
v 639893144 265359784 646791226
v 796871409 411409966 598676495
v 882562617 224394...

output:

393120558 -224477738 387297348
-238284787 981774500 -870231856
-703632542 980011608 -464602324
-593864779 745296852 -944750793
404565501 -169374593 78021156
-405749495 -350493049 -116816620
190018467 515243135 518180555
-370063853 -488259799 -740814218
-984507108 -646156562 -80833866
-66193044 -6316...

result:

ok 300000 numbers

Test #3:

score: 0
Accepted
time: 371ms
memory: 38272kb

input:

199999 100000
x 154525 80092
v 450407262 725458410 590777520
x 24720 135901
v 719242117 114943104 186796011
v 382530926 89156744 943939337
x 183376 26042
x 109984 157873
x 151637 150600
x 4115 27454
x 163135 92648
x 16764 33212
v 849210403 945083972 689295397
v 471196117 68587428 225597765
x 24643 5...

output:

-321176892 996514296 449166851
810403092 258196842 -144784620
410756156 -744895835 -85579882
327134890 -478998570 922528759
317367558 536888537 -492030244
-513490823 879045782 -225839405
422920052 152084658 -480903896
1207902 348787162 -677423276
776293878 699474926 -287129823
-126385880 468497588 -...

result:

ok 300000 numbers

Test #4:

score: 0
Accepted
time: 365ms
memory: 38216kb

input:

199999 100000
x 72889 193806
x 35339 33069
v 314802407 406980523 492377265
x 108307 60027
x 144922 140917
v 328481079 117663280 644171354
v 482028404 951751561 166221217
v 936461869 436114879 421819757
x 152919 99965
x 61168 150607
v 56403640 743462679 134896557
v 24809217 462947115 966139991
v 7828...

output:

-974534477 380448367 629159667
-237565933 539369190 611778104
114926687 653692915 939877414
-324044883 304745735 544123803
-44444241 186017361 49200537
327282782 -127242676 -704263640
588783157 -496113704 -807680056
-895563447 993889016 963478755
-488231872 105416897 281770975
-187161547 367139818 4...

result:

ok 300000 numbers

Test #5:

score: 0
Accepted
time: 357ms
memory: 38312kb

input:

199999 100000
x 134204 79203
v 152855933 152545887 271660214
v 393332175 182708769 115884220
v 731792305 965028257 676889584
x 89631 14495
x 142016 85686
v 600051847 172947969 906920949
v 846126215 214556203 657929902
x 125721 133526
x 93179 35713
v 330716449 450417250 611411649
v 114397688 58644961...

output:

139597616 375474977 -983624560
-108915893 79727434 363703631
-600893251 -120282751 429046190
-409876008 -178818454 502148739
520578911 186408072 -513870808
997888597 816534316 -659833074
334166269 288211584 608252640
-488963508 362972392 286415695
-634847393 -119363102 -994585898
-286973481 -9034278...

result:

ok 300000 numbers

Test #6:

score: 0
Accepted
time: 381ms
memory: 38384kb

input:

199999 100000
x 29842 60343
x 22382 27649
v 148997533 411153785 529195552
v 831453378 856711025 439562917
x 183061 152107
v 208562249 845550020 248974502
x 8708 152913
v 901332053 480035531 424365358
v 120556946 620074725 884675784
v 493886564 455460926 851190410
x 63346 64739
x 35246 36255
v 762936...

output:

236797322 -808025939 70559261
-336478455 266356472 481630021
-587276683 613729303 804008156
92638320 -960317575 82924205
-640374470 232766711 -418635821
-306542271 124868602 -810877141
237610689 -389754505 581104410
848616732 -90371214 859807891
-383619738 454674844 -324614686
485784731 743926138 16...

result:

ok 300000 numbers

Test #7:

score: 0
Accepted
time: 377ms
memory: 38360kb

input:

199999 100000
x 179471 175117
x 189060 178495
x 20142 58065
x 22916 150184
v 704047412 186112247 660817663
v 761554808 199099716 794321264
v 362925435 508140595 251556541
v 65674025 717152823 157775106
v 325965317 977108704 50644678
v 566946741 833186394 771714200
v 996708965 76780827 625429369
v 85...

output:

-632986028 -892414579 -385846523
-266735298 576900445 663777200
-444725676 -582790078 7683807
-530113104 -421018422 513594285
215590236 -137098079 -185423961
-328258557 229486834 564691763
929231866 -478016304 -223634605
-968294064 569366391 -277172238
-353671246 -484529715 554458153
-270237152 -574...

result:

ok 300000 numbers

Test #8:

score: 0
Accepted
time: 386ms
memory: 38644kb

input:

199999 100000
x 73506 171332
x 135330 187765
v 308206068 679940956 278078069
v 442448744 196158033 738117032
x 194709 115786
v 208526122 936976225 340056181
x 42663 43401
x 55484 199464
v 865443128 131903961 74265613
x 44659 44773
x 32199 18455
v 986118756 284329619 244212114
v 793747964 649179736 4...

output:

-568527314 868308596 175018519
966246118 532451840 773132006
-541158255 -366456073 -8555110
-447669502 6706768 416615899
-713103269 505326489 916518702
-540778964 -344714109 951605771
614211832 -230416296 -953970559
698196640 494937773 99337798
-279741119 -576166316 151379051
-977724006 -291100520 7...

result:

ok 300000 numbers

Test #9:

score: 0
Accepted
time: 375ms
memory: 38700kb

input:

199999 100000
x 109220 170287
v 563361501 367416904 98790213
x 31431 96958
x 99594 159052
x 95382 129615
v 61965807 547448247 405891792
v 443530416 578856323 588763197
v 761021716 795533831 212530056
v 370964907 391812631 255457982
x 49713 153066
x 141543 111694
v 144135957 614962153 284136518
x 416...

output:

-564950391 -661330106 -250875550
992117520 9180464 -838628109
483825959 -501508520 964507719
912495370 737285784 595438897
467123496 44306423 562070292
-94756115 42971643 -936828694
-728391208 -661502862 565138878
926999098 134871683 -720629537
-353517322 -521919528 69621281
-13375740 -885653793 688...

result:

ok 300000 numbers

Test #10:

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

input:

3 1
x 2 3
v 998244352 998244352 998244352
v 0 0 0
3 1 2 0

output:

-998244351 998244352 998244352

result:

ok 3 number(s): "2 998244352 998244352"

Test #11:

score: 0
Accepted
time: 389ms
memory: 39156kb

input:

199999 100000
x 199465 1690
x 70268 106693
v 194793703 729830314 457557419
x 64673 6910
v 755452906 141328541 558160677
v 725017524 158685295 201414156
x 161801 27226
x 181414 47025
v 387724146 819109666 514628998
v 252532326 97757436 828777580
v 200868967 692540096 706977766
v 300419109 2053530 824...

output:

-371033836 -357298462 400484640
-692602867 893058825 -898351186
-262515265 -192648820 283037791
377070714 357962902 -661458804
-162305673 -363549622 22388934
493696932 612552793 -481299119
963890355 517530875 48223226
-782926273 -255660608 -618453331
-863169608 970450812 -76420073
-911671971 4816962...

result:

ok 300000 numbers

Test #12:

score: 0
Accepted
time: 383ms
memory: 40388kb

input:

199999 100000
x 37758 141919
v 148792593 369372129 595139892
x 59335 149367
v 452667329 904801829 628919068
v 160106559 532238331 179544300
v 850489754 705167899 265598880
x 120963 167491
x 92157 46815
v 444945978 987276260 843838004
x 189040 28027
v 889755401 760730228 3237333
x 168907 82672
v 2329...

output:

-101058855 177437016 -344597551
-949384144 -114729541 764698776
505088312 585962448 -452153958
-83998326 -457300186 682989725
-32409202 803706423 302298107
452996535 -283460866 -36392156
882717809 -572284599 886391042
203667304 454663502 -920138631
-486048218 -271026126 418204527
-723309552 27097736...

result:

ok 300000 numbers

Extra Test:

score: 0
Extra Test Passed