QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185251#5174. 青蛙思直线xuqin15 1384ms68824kbC++145.0kb2023-09-21 19:59:232023-09-21 19:59:24

Judging History

This is the latest submission verdict.

  • [2023-09-21 19:59:24]
  • Judged
  • Verdict: 15
  • Time: 1384ms
  • Memory: 68824kb
  • [2023-09-21 19:59:23]
  • Submitted

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cassert>
#include<set>
#include<bitset>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<iostream>

using namespace std;
const int maxn=1e5+5, maxm=2e3+5, inf=2e9, P=998244353, bs=661;
const double eps=1e-10, pi=3.1415926535897932384;
typedef long long LL;
typedef unsigned long long ULL;
const LL INF=4e18;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
inline int read() {
	int x=0, f=1; char c=getchar();
	for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=0;
	for(; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
	return f?x:-x;
}

inline int add(int x, int y) {x+=y; return x>=P?x-P:x;}
inline int del(int x, int y) {x-=y; return x<0?x+P:x;}
inline int ksm(int x, int y) {
	int s=1; for(; y; y>>=1, x=1LL*x*x%P) if(y&1) s=1LL*s*x%P; return s;
}
struct pj{
	int a[3][3];
	pj() {memset(a, 0, sizeof a);}
	void set1() {
		for(int i=0; i<3; ++i) for(int j=0; j<3; ++j) a[i][j]=i==j; 
	}
	pj operator*(const pj& b) const {
		pj c;
		for(int i=0; i<3; ++i)
			for(int k=0; k<3; ++k)
				for(int j=0; j<3; ++j) c.a[i][j]=add(c.a[i][j], 1LL*a[i][k]*b.a[k][j]%P);
		return c;
	}
};

pj mat(int a, int b, int c) {
	pj ret; int inv=ksm((1LL*a*a+1LL*b*b)%P, P-2);
	ret.a[0][0]=1LL*del(1LL*b*b%P, 1LL*a*a%P)*inv%P;
	ret.a[1][1]=del(0, ret.a[0][0]);
	ret.a[1][0]=ret.a[0][1]=del(0, 2LL*a*b%P*inv%P);
	ret.a[2][0]=del(0, 2LL*a*c%P*inv%P);
	ret.a[2][1]=del(0, 2LL*b*c%P*inv%P);
	ret.a[2][2]=1;
	return ret;
}
pj mat(int x0, int y0, int a, int b, int c) {
	int co=ksm(c, P-2), si=1LL*a*co%P; co=1LL*co*b%P; pj ret;
	ret.a[0][0]=ret.a[1][1]=co; ret.a[0][1]=si; ret.a[1][0]=del(0, si);
	ret.a[2][0]=add(del(x0, 1LL*x0*co%P), 1LL*y0*si%P);
	ret.a[2][1]=del(del(y0, 1LL*x0*si%P), 1LL*y0*co%P);
	ret.a[2][2]=1;
	return ret;
}
pj mat(int x, int y) {
	pj ret;
	ret.a[0][0]=x, ret.a[0][1]=y, ret.a[0][2]=1;
	return ret;
}

struct tg{
	pj val, nval, tagl, tagr; int tag;
} tr[maxn<<2];
pj a[maxn], na[maxn];

void build(int u, int l, int r) {
	tr[u].tagl.set1(); tr[u].tagr.set1(); tr[u].tag=0;
	if(l==r) {
		tr[u].val=a[l];
		tr[u].nval=na[l];
		return;
	}
	int mid=(l+r)>>1;
	build(u<<1, l, mid); build(u<<1|1, mid+1, r);
	tr[u].val=tr[u<<1].val*tr[u<<1|1].val;
	tr[u].nval=tr[u<<1].nval*tr[u<<1|1].nval;
}
void pushdown(int u) {
	tr[u<<1].val=tr[u].tagl*tr[u<<1].val*tr[u].tagr,
	tr[u<<1].nval=tr[u].tagl*tr[u<<1].nval*tr[u].tagr,
	tr[u<<1|1].val=tr[u].tagl*tr[u<<1|1].val*tr[u].tagr;
	tr[u<<1|1].nval=tr[u].tagl*tr[u<<1|1].nval*tr[u].tagr;
	if(tr[u].tag) 
		swap(tr[u<<1].val, tr[u<<1].nval), swap(tr[u<<1|1].val, tr[u<<1|1].nval),
		tr[u<<1].tag^=1, tr[u<<1|1].tag^=1;
	tr[u].tag=0; tr[u].tagl.set1(); tr[u].tagr.set1();
}
void modify(int u, int l, int r, int l0, int r0, pj nm, pj m, int rev) {
	if(l0<=l&&r<=r0) {
		tr[u].val=nm*tr[u].val*m;
		tr[u].nval=nm*tr[u].nval*m;
		tr[u].tagl=nm*tr[u].tagl;
		tr[u].tagr=tr[u].tagr*m;
		if(rev) tr[u].tag^=1, swap(tr[u].val, tr[u].nval);
		return;
	}
	pushdown(u);
	int mid=(l+r)>>1;
	if(l0<=mid) modify(u<<1, l, mid, l0, r0, nm, m, rev);
	if(r0>mid) modify(u<<1|1, mid+1, r, l0, r0, nm, m, rev);
	tr[u].val=tr[u<<1].val*tr[u<<1|1].val;
	tr[u].nval=tr[u<<1].nval*tr[u<<1|1].nval;
}

pj query(int u, int l, int r, int l0, int r0) {
	if(l0<=l&&r<=r0) return tr[u].val;
	int mid=(l+r)>>1; pushdown(u);
	pj ret; ret.set1();
	if(l0<=mid) ret=ret*query(u<<1, l, mid, l0, r0);
	if(r0>mid) ret=ret*query(u<<1|1, mid+1, r, l0, r0); 
	return ret;
}

int main() {
	int n=read(), q=read();
	for(int i=1; i<=n; ++i) {
		int ty=read();
		if(ty==1) {
			int aa=(read()%P+P)%P, bb=(read()%P+P)%P, cc=(read()%P+P)%P;
			a[i]=na[i]=mat(aa, bb, cc);
		} else if(ty==2) {
			int x0=(read()%P+P)%P, y0=(read()%P+P)%P, aa=(read()%P+P)%P, bb=(read()%P+P)%P, cc=(read()%P+P)%P;
			a[i]=mat(x0, y0, aa, bb, cc);
			na[i]=mat(x0, y0, del(0, aa), bb, cc);
		}
	}
	build(1, 1, n); 
	for(int ty; q--; ) {
		ty=read();
		if(ty==1) {
			int x=(read()%P+P)%P, y=(read()%P+P)%P, l=read(), r=read();
			pj ans=mat(x, y)*query(1, 1, n, l, r);
			//pj ans=mat(x, y);
			//for(int i=l; i<=r; ++i) ans=ans*a[i];
			printf("%d %d\n", ans.a[0][0], ans.a[0][1]);
		} else if(ty==2) {
			int aa=(read()%P+P)%P, bb=(read()%P+P)%P, cc=(read()%P+P)%P, l=read(), r=read();
			modify(1, 1, n, l, r, mat(aa, bb, cc), mat(aa, bb, cc), 1);
			//for(int i=l; i<=r; ++i)
			//	a[i]=mat(aa, bb, cc)*a[i]*mat(aa, bb, cc),
			//	na[i]=mat(aa, bb, cc)*na[i]*mat(aa, bb, cc), swap(a[i], na[i]); 
		} else if(ty==3) {
			int x0=(read()%P+P)%P, y0=(read()%P+P)%P, aa=(read()%P+P)%P, bb=(read()%P+P)%P, cc=(read()%P+P)%P, l=read(), r=read();
			modify(1, 1, n, l, r, mat(x0, y0, del(0, aa), bb, cc), mat(x0, y0, aa, bb, cc), 0);
			//for(int i=l; i<=r; ++i)
			//	a[i]=mat(x0, y0, del(0, aa), bb, cc)*a[i]*mat(x0, y0, aa, bb, cc),
			//	na[i]=mat(x0, y0, del(0, aa), bb, cc)*na[i]*mat(x0, y0, aa, bb, cc);
		}
	} 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 68760kb

input:

100 100
2 -83858883 861333371 661061160 -36361 661061161
2 -532239730 -922334866 -601732740 34691 601732741
2 435055696 355222897 -13400664 5177 13400665
1 467023120 -892412460 -149231532
2 -144866214 -906803104 515493940 32109 515493941
1 -189225996 -528898393 -977898040
2 384013409 479885502 23339...

output:

112770071 375154894
116498870 247766445
297455298 376038437
614898067 989343769
248897993 846775784
620985644 912478278
387187398 688005343
121532103 955643429
422262452 662920301
575104984 580994169
74116160 891090169
871134159 201842903
518985318 552706910
372958241 638877003
378344269 196223051
1...

result:

wrong answer 2nd lines differ - expected: '448466645 615321617', found: '116498870 247766445'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 1354ms
memory: 68660kb

input:

100000 100000
1 -192197612 115190605 767194240
1 -198216180 -511433295 95040803
1 -203884367 -410636373 529475286
1 -587263021 -518957051 -289336078
1 75253754 687544707 363669312
1 -824939819 -978504413 201885662
1 -163357186 -589177000 264718223
1 -875813550 497550093 -797162432
1 -108811248 -9249...

output:

841029342 305450907
835277601 540236432
150988838 816396904
584457695 318155582
124480352 897045904
328461194 454907170
548458947 817900393
737916203 513488134
687082844 537651680
856555160 351948803
351645208 901197418
753223996 928599918
584789499 577529180
857098631 635767934
204212896 439142654
...

result:

wrong answer 1st lines differ - expected: '110357117 282199239', found: '841029342 305450907'

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 1384ms
memory: 68708kb

input:

100000 100000
2 404809633 -19259508 -21747 -236466004 236466005
2 -660732477 817220029 33793 570983424 570983425
2 861959162 -761827146 -22357984 6687 22357985
2 -202139172 147507338 -325967044 25533 325967045
2 485261767 778145842 43241 934892040 934892041
2 607873212 479867690 879523740 41941 8795...

output:

389281309 613969428
839329953 600506097
907053564 77450776
782490735 908141735
968038734 793870031
328994252 868151421
902270381 564436566
716521846 189129196
933547908 451069083
638343022 376339305
877049981 809413265
784752360 415268144
430756749 971932877
23676680 329377864
27952383 709491778
602...

result:

wrong answer 1st lines differ - expected: '324353430 572978305', found: '389281309 613969428'

Subtask #5:

score: 15
Accepted

Test #21:

score: 15
Accepted
time: 1128ms
memory: 68724kb

input:

100000 100000
1 -109326083 -252045233 -753228979
1 54024079 690286325 776569314
1 826611314 -911535025 -823690431
1 -355380330 -552996520 -850686699
1 649346459 -852374490 90437104
1 -294870656 595413398 808089519
1 399638191 519980860 565184319
2 -644934515 -209540084 -395001724 28107 395001725
2 -...

output:

552415227 948498653
956038420 98682956
994098267 402635356
356618613 612376558
77382305 51497509
513057564 541174297
582727445 14500865
255428579 680584682
939824955 676694888
423138002 6968775
545400319 529731423
206843123 249021137
348432938 619418681
902448830 178805727
904036520 36114150
4761339...

result:

ok 100000 lines

Test #22:

score: 0
Accepted
time: 1141ms
memory: 68576kb

input:

100000 100000
2 403048 -953877450 29867 -446018844 446018845
2 525100699 74382339 347240304 26353 347240305
2 781476041 279030959 34536360 8311 34536361
2 512872227 837860402 178623900 18901 178623901
2 -734737559 -212977985 -38831 753923280 753923281
2 -962276684 -496355715 826333204 -40653 8263332...

output:

853295516 269178788
461499077 450530718
856617652 298371798
336977932 840085951
109448216 993857775
458624009 378098643
859307871 311415019
296695075 168182042
896213596 302793225
903150312 236280415
597820533 170770156
880193207 33354785
520902452 475635332
639786021 926653237
318563587 664980135
8...

result:

ok 100000 lines

Test #23:

score: 0
Accepted
time: 1141ms
memory: 68684kb

input:

100000 100000
1 289130240 -270850298 990077565
1 27546030 -407978535 631684432
2 -120550573 -257418235 -34403 -591783204 591783205
1 96971172 -669733959 -277187342
2 -531893563 -147746735 -532325820 -32629 532325821
1 255056370 123582163 -226365814
1 -877485119 -351652822 101965837
2 972370717 -6988...

output:

306678969 149081272
902764788 507681352
622171186 688132591
322238221 666986936
626070286 635480998
977944037 550237892
742931577 449868323
718815935 590416125
274915750 858049350
927685503 618458683
54942033 274197313
614750753 817940104
240372820 233871096
187093076 364981594
718660991 755076816
4...

result:

ok 100000 lines

Test #24:

score: 0
Accepted
time: 1129ms
memory: 68824kb

input:

100000 100000
1 -330845879 -569868992 -407549992
1 302572571 -729144001 139642218
2 -494748809 -602469273 908786344 42633 908786345
2 344910074 -649464363 -14879 110692320 110692321
2 -334413419 669933053 38627 746022564 746022565
1 -998923494 -639820129 -59255645
2 -398742551 -209456788 -599653080 ...

output:

211894655 967076478
91082630 845734675
229277374 813469918
443982315 523917497
709328939 489251635
762197866 704338870
994554804 33524263
659527556 10890265
947655403 251573825
347852331 673858107
805533786 849348732
983082526 682280296
590091151 94383160
943466413 998164271
745957565 496490060
2826...

result:

ok 100000 lines

Test #25:

score: 0
Accepted
time: 1139ms
memory: 68716kb

input:

100000 100000
2 -43355511 862697708 -16410720 5729 16410721
1 -374058922 753724403 683601267
2 -625118146 -38065446 236944680 -21769 236944681
1 639413098 431423728 100212485
2 -997801273 -5449010 33366280 -8169 33366281
1 -881323971 646326299 478084353
2 544455014 -694718413 -10601 -56190600 561906...

output:

886489104 989219459
278712918 883745306
141505831 355222512
518214173 757808670
106954934 289248823
98417705 416836480
353039396 97895976
505908242 686163372
666273487 943709433
760339882 924560883
616072451 139641035
770135915 997112295
970911121 767818383
247599418 658977441
211720307 767892738
34...

result:

ok 100000 lines

Subtask #6:

score: 0
Skipped

Dependency #2:

0%