QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#544065#8133. When Anton Saw This Task He Reacted With 😩PhantomThresholdAC ✓1106ms74892kbC++204.5kb2024-09-02 02:23:202024-09-02 02:23:20

Judging History

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

  • [2024-09-02 02:23:20]
  • 评测
  • 测评结果:AC
  • 用时:1106ms
  • 内存:74892kb
  • [2024-09-02 02:23:20]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int MOD=998244353;

struct mat
{
	int a[3][3];
	mat(){memset(a,0,sizeof(a));}
	mat operator*(const mat &m)const
	{
		mat ret;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					ret.a[i][k]+=a[i][j]*m.a[j][k];
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				ret.a[i][j]%=MOD;
		return ret;
	}
};
struct vc
{
	int x,y,z;
	vc operator+(const vc &k)const{return (vc){(x+k.x)%MOD,(y+k.y)%MOD,(z+k.z)%MOD};}
	vc operator-(const vc &k)const{return (vc){(x-k.x)%MOD,(y-k.y)%MOD,(z-k.z)%MOD};}
	vc operator*(const int k)const{return (vc){(x*k)%MOD,(y*k)%MOD,(z*k)%MOD};}
	vc operator*(const vc &k)const{return (vc){(y*k.z-z*k.y)%MOD,(z*k.x-x*k.z)%MOD,(x*k.y-y*k.x)%MOD};}
	vc operator*(const mat &m)const{return (vc){(x*m.a[0][0]+y*m.a[1][0]+z*m.a[2][0])%MOD,(x*m.a[0][1]+y*m.a[1][1]+z*m.a[2][1])%MOD,(x*m.a[0][2]+y*m.a[1][2]+z*m.a[2][2])%MOD};}
//	vc operator^(const vc &k)const{return (vc){(x*k.x)%MOD,(y*k.y)%MOD,(z*k.z)%MOD};}
	mat conv(int ty)//L/R
	{
		mat ret;
		/*
		  o
		 / .
		o   o
		*/
		if(ty==1)
		{
			ret.a[0][0]=0;ret.a[0][1]=-z;ret.a[0][2]=y;
			ret.a[1][0]=z;ret.a[1][1]=0;ret.a[1][2]=-x;
			ret.a[2][0]=-y;ret.a[2][1]=x;ret.a[2][2]=0;
		}
		/*
		  o
		 . \
		o   o
		*/
		else
		{
			ret.a[0][0]=0;ret.a[0][1]=z;ret.a[0][2]=-y;
			ret.a[1][0]=-z;ret.a[1][1]=0;ret.a[1][2]=x;
			ret.a[2][0]=y;ret.a[2][1]=-x;ret.a[2][2]=0;
		}
		return ret;
	}
	friend ostream& operator<<(ostream &os,const vc &k){os<<k.x<<' '<<k.y<<' '<<k.z;return os;}
};
const int MAXN=555555;
mat seg[MAXN];
int lson[MAXN],rson[MAXN];
int top0,root;
int build(int l,int r)
{
	int ret=++top0;
	if(l!=r)
	{
		int mid=(l+r)/2;
		ret[lson]=build(l,mid);
		ret[rson]=build(mid+1,r);
	}
	return ret;
}
void upd(int cur)
{
	cur[seg]=cur[rson][seg]*cur[lson][seg];
}
void change(int cur,int l,int r,int pos,const mat &m)
{
	if(l==r)
	{
		cur[seg]=m;
		return;
	}
	int mid=(l+r)/2;
	if(pos<=mid)change(cur[lson],l,mid,pos,m);
	else change(cur[rson],mid+1,r,pos,m);
	upd(cur);
}
vc query(int cur,int l,int r,int ql,int qr,const vc &v)
{
	if(l==ql and r==qr)return v*cur[seg];
	int mid=(l+r)/2;
	if(qr<=mid)return query(cur[lson],l,mid,ql,qr,v);
	else if(ql>=mid+1)return query(cur[rson],mid+1,r,ql,qr,v);
	else
	{
		auto tv=query(cur[rson],mid+1,r,mid+1,qr,v);
		return query(cur[lson],l,mid,ql,mid,tv);
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n,q;
	
	cin>>n>>q;
	vector<vc> a(n+5);
	vector<int> L(n+5),R(n+5),pa(n+5);
	for(int i=1;i<=n;i++)
	{
		string ty;
		cin>>ty;
		if(ty=="x")
		{
			cin>>L[i]>>R[i];
			pa[L[i]]=i;pa[R[i]]=i;
		}
		else
		{
			cin>>a[i].x>>a[i].y>>a[i].z;
		}
	}
	
	root=build(1,n);
	
	vector<int> siz(n+5),dep(n+5),ty(n+5),dfn(n+5),top(n+5),bot(n+5);
	function<void(int)> dfs1=[&](int u)
	{
		siz[u]=1;
		if(L[u])
		{
			dep[L[u]]=dep[u]+1;
			dfs1(L[u]);
			dep[R[u]]=dep[u]+1;
			dfs1(R[u]);
			siz[u]+=siz[L[u]]+siz[R[u]];
			if(siz[L[u]]>siz[R[u]])
				ty[u]=0,bot[u]=bot[L[u]];
			else
				ty[u]=1,bot[u]=bot[R[u]];
		}
		else
		{
			bot[u]=u;
		}
	};
	dep[1]=1;
	dfs1(1);
	
	auto updt=[&](int u)
	{
//		cerr<<"updt "<<u<<endl;
		if(ty[u]==0)
		{
			auto tv=a[bot[R[u]]];
			if(bot[R[u]]!=top[R[u]])
			{
				tv=query(root,1,n,dfn[R[u]],dfn[pa[bot[R[u]]]],tv);
			}
//			cerr<<tv<<endl;
			change(root,1,n,dfn[u],tv.conv(1));
		}
		else
		{
			auto tv=a[bot[L[u]]];
			if(bot[L[u]]!=top[L[u]])
			{
				tv=query(root,1,n,dfn[L[u]],dfn[pa[bot[L[u]]]],tv);
			}
//			cerr<<tv<<endl;
			change(root,1,n,dfn[u],tv.conv(0));
		}
	};
	
	int idx=0;
	function<void(int)> dfs2=[&](int u)
	{
		dfn[u]=++idx;
		if(L[u])
		{
			if(ty[u]==0)
			{
				top[L[u]]=top[u];
				dfs2(L[u]);
				top[R[u]]=R[u];
				dfs2(R[u]);
			}
			else
			{
				top[R[u]]=top[u];
				dfs2(R[u]);
				top[L[u]]=L[u];
				dfs2(L[u]);
			}
			updt(u);
		}
	};
	top[1]=1;
	dfs2(1);
	
	/*
	cerr<<"i\tdfn\tty\ttop\tbot\n";
	for(int i=1;i<=n;i++)
	{
		cerr<<i<<'\t'<<dfn[i]<<'\t'<<ty[i]<<'\t'<<top[i]<<'\t'<<bot[i]<<endl;
	}
	*/
	for(int i=1;i<=q;i++)
	{
		int pos;
		vc d;
		cin>>pos>>d.x>>d.y>>d.z;
		
		a[pos]=d;
		pos=pa[top[pos]];
		while(pos)
		{
			updt(pos);
			pos=pa[top[pos]];
		}
		
		auto tv=a[bot[1]];
		tv=query(root,1,n,dfn[1],dfn[pa[bot[1]]],tv);
//		cerr<<"ans"<<endl;
		cout<<tv.x<<' '<<tv.y<<' '<<tv.z<<"\n";
	}
	
	cerr<<clock()<<endl;
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1106ms
memory: 69736kb

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:

-605123795 773766615 387297348
759959566 981774500 -870231856
-703632542 -18232745 533642029
404379574 745296852 53493560
-593678852 -169374593 -920223197
592494858 647751304 881427733
-808225886 -483001218 518180555
-370063853 509984554 -740814218
13737245 352087791 917410487
-66193044 366591227 -5...

result:

ok 300000 numbers

Test #3:

score: 0
Accepted
time: 932ms
memory: 69772kb

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 -549077502
810403092 258196842 853459733
410756156 253348518 -85579882
327134890 519245783 922528759
317367558 536888537 -492030244
-513490823 879045782 772404948
422920052 -846159695 -480903896
-997036451 348787162 320821077
-221950475 699474926 -287129823
-126385880 468497588 ...

result:

ok 300000 numbers

Test #4:

score: 0
Accepted
time: 734ms
memory: 69544kb

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:

23709876 380448367 629159667
-237565933 -458875163 -386466249
-883317666 -344551438 939877414
-324044883 -693498618 544123803
-44444241 -812226992 49200537
327282782 -127242676 -704263640
588783157 502130649 -807680056
-895563447 993889016 963478755
510012481 105416897 -716473378
-187161547 36713981...

result:

ok 300000 numbers

Test #5:

score: 0
Accepted
time: 645ms
memory: 69712kb

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 -622769376 14619793
-108915893 -918516919 -634540722
397351102 -120282751 -569198163
588368345 -178818454 502148739
-477665442 186408072 -513870808
997888597 816534316 338411279
334166269 288211584 -389991713
509280845 -635271961 -711828658
-634847393 878881251 -994585898
-286973481 948165...

result:

ok 300000 numbers

Test #6:

score: 0
Accepted
time: 568ms
memory: 69884kb

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 -927685092
-336478455 -731887881 481630021
-587276683 -384515050 -194236197
92638320 -960317575 -915320148
-640374470 -765477642 -418635821
691702082 -873375751 187367212
-760633664 -389754505 -417139943
-149627621 -90371214 -138436462
-383619738 454674844 673629667
-512459622 -...

result:

ok 300000 numbers

Test #7:

score: 0
Accepted
time: 564ms
memory: 70348kb

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 -421343908 663777200
553518677 415454275 7683807
468131249 577225931 513594285
215590236 -137098079 -185423961
-328258557 229486834 564691763
929231866 520228049 -223634605
-968294064 -428877962 721072115
644573107 513714638 -443786200
-270237152 -57439702...

result:

ok 300000 numbers

Test #8:

score: 0
Accepted
time: 583ms
memory: 70728kb

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:

429717039 868308596 -823225834
966246118 532451840 773132006
457086098 -366456073 -8555110
-447669502 6706768 -581628454
-713103269 505326489 -81725651
457465389 -344714109 951605771
-384032521 767828057 -953970559
698196640 -503306580 -898906555
718503234 422078037 -846865302
20520347 -291100520 -2...

result:

ok 300000 numbers

Test #9:

score: 0
Accepted
time: 584ms
memory: 70932kb

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:

433293962 -661330106 747368803
992117520 9180464 159616244
483825959 496735833 -33736634
-85748983 -260958569 -402805456
467123496 -953937930 -436174061
-94756115 -955272710 -936828694
-728391208 336741491 -433105475
-71245255 134871683 -720629537
-353517322 476324825 69621281
-13375740 112590560 -3...

result:

ok 300000 numbers

Test #10:

score: 0
Accepted
time: 3ms
memory: 45452kb

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: 569ms
memory: 72116kb

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 640945891 400484640
305641486 893058825 99893167
-262515265 -192648820 -715206562
377070714 357962902 336785549
835938680 -363549622 -975855419
-504547421 612552793 -481299119
963890355 -480713478 48223226
-782926273 -255660608 379791022
135074745 -27793541 921824280
86572382 -516548109 7...

result:

ok 300000 numbers

Test #12:

score: 0
Accepted
time: 480ms
memory: 74892kb

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:

897185498 -820807337 -344597551
-949384144 -114729541 764698776
-493156041 -412281905 546090395
914246027 -457300186 -315254628
-32409202 -194537930 302298107
452996535 714783487 -36392156
882717809 425959754 886391042
203667304 454663502 78105722
-486048218 -271026126 418204527
274934801 -727266992...

result:

ok 300000 numbers

Extra Test:

score: 0
Extra Test Passed