QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185786 | #5174. 青蛙思直线 | xuqin | 20 | 164ms | 68804kb | C++14 | 4.9kb | 2023-09-22 16:41:52 | 2023-09-22 16:41:52 |
Judging History
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: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 68804kb
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 448466645 615321617 136296103 188519266 753978971 307529669 464263489 417472847 967235693 670671324 898492556 245574178 489201249 912205294 217317832 293377572 71676569 463049938 897010602 680630200 896018703 764607822 633595334 179613322 548187858 628842862 97720933 983039131 20...
result:
ok 39 lines
Test #2:
score: 0
Accepted
time: 6ms
memory: 68688kb
input:
100 100 2 -8707061 -698854750 221614404 -21053 221614405 1 -493241664 -671774466 386156567 2 406369035 -892336356 -41733 870821644 870821645 2 -719311291 745349826 -10157 51582324 51582325 2 -507581835 -766162770 -122512 495 122513 2 717216052 -489487324 -636424164 35677 636424165 1 -764548879 -8730...
output:
537902090 20665174 914763446 486778863 715923139 41076082 202361267 328271833 663291283 18486594 428867933 617259887 82834551 436940488 804696725 943638316 617008570 988106644 67809899 781756527 709844447 641389980 832851171 823406117 576230034 368053436 347791486 216966120 887300868 445447 99531751...
result:
ok 36 lines
Test #3:
score: 0
Accepted
time: 7ms
memory: 68696kb
input:
100 100 2 -514977264 -134950646 -61600 -351 61601 2 256668375 741455283 -363663480 26969 363663481 2 468409299 -607034661 517229284 -32163 517229285 2 -312102810 9926660 43623 -951483064 951483065 1 519204965 -293764509 -388913781 1 672240773 476598341 693213162 1 364639136 -388304610 -668484674 2 -...
output:
52085690 346833362 974296848 772299462 845023614 940492895 393581447 442003555 384970682 13567295 381443012 296619745 145132968 176010594 288656575 979893596 284660597 171383889 494694961 632782793 360626434 196453592 271591957 545489922 161392032 842340374 486022531 285758847 312571865 165117554 66...
result:
ok 44 lines
Test #4:
score: 0
Accepted
time: 3ms
memory: 68688kb
input:
100 100 1 -425242946 -992048175 689952320 1 -267560133 -26450535 361963906 2 257638778 290389317 2002000 -2001 2002001 2 -552608453 521355580 17953 161155104 161155105 1 -263398448 989004792 -431463918 2 -682165566 -786526835 -205254060 -20261 205254061 2 579703401 -857131598 -266550960 23089 266550...
output:
399630486 716121410 377317276 499827686 113694308 240642926 406625474 779684613 477619539 160059108 572562993 257709281 456370845 857272243 23298680 489388969 76105213 527948480 14803936 845204380 715615123 78448011 766819557 573215402 408098045 428555546 612747231 433423908 836028434 580598350 7127...
result:
ok 35 lines
Test #5:
score: 0
Accepted
time: 4ms
memory: 68688kb
input:
100 100 1 -847248913 -864138113 -704498105 1 -888183295 168694792 620342083 1 440006339 -120273382 44646172 2 -643984319 440718760 18909 178775140 178775141 1 -452372002 -635102847 17190430 1 588126919 -640031128 428666660 1 -822569246 645125492 310289240 2 606755191 -784387904 -2304804 2147 2304805...
output:
144678237 54639051 11737045 620056438 298175064 191544406 176564118 943438697 879440893 803048426 645330687 762371306 936240032 822381358 918433616 89028160 715359234 903057293 504489564 727644057 850645754 78543508 828753134 417061674 653987994 500169418 708009548 834035341 931145733 397753023 9122...
result:
ok 39 lines
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 10
Accepted
time: 161ms
memory: 68700kb
input:
1000 1000 1 -688493041 -34676380 -807675251 1 -246734297 -967532271 949440723 1 -429982204 -556363291 -788572454 2 -239328851 860082047 33859 573215940 573215941 2 -314933245 409182866 14037 98518684 98518685 2 815835187 448245997 8511 36218560 36218561 2 777652100 -895346785 -226525612 21285 226525...
output:
183924538 580381026 141666620 104774061 263910551 929345261 980957693 465699256 184419662 941374595 227314712 523864542 301657124 852982682 251909570 391797967 461324658 700100306 4194915 64690629 380217284 464473450 578561199 94571681 108000840 571195647 68853655 420383040 187290788 848486352 23380...
result:
ok 337 lines
Test #7:
score: 0
Accepted
time: 160ms
memory: 68652kb
input:
1000 1000 1 83732518 472073626 432807387 1 629317119 406701703 471601642 2 -9686139 613092403 12177112 -4935 12177113 1 689004582 134667728 304784885 1 937317852 -846979938 -486483463 1 915383231 -178849275 891413582 2 876049555 717676886 -75509760 12289 75509761 1 513362709 -27236062 -447390204 1 -...
output:
609088757 314685964 828797681 327382738 355157172 106663403 691716562 825260881 400203480 181258440 922199709 301425820 42006172 318874026 221048553 604424181 263536028 422505173 157876357 787666721 537718376 14825978 586510617 598194700 955495161 488357561 698083208 643373543 49688141 66762071 9237...
result:
ok 308 lines
Test #8:
score: 0
Accepted
time: 159ms
memory: 68696kb
input:
1000 1000 1 -529111236 -149864883 -246584272 1 741032192 -120714322 196692843 2 815455198 -867972868 -55444 -333 55445 2 -896165294 895187963 16493 136009524 136009525 2 -909807417 699026706 -273335580 -23381 273335581 1 456466703 -955408135 -36431142 1 -211423834 -176325564 751934183 1 -353045306 -...
output:
825407310 930804294 398546478 325428202 382198066 103086404 858889576 914288378 984943357 941807744 518604280 346051939 869319612 394951279 57174909 428413210 835791532 358415476 639631156 355030610 745935997 776576070 590401490 712440406 710753279 966689537 968800331 799026527 460939788 145675402 4...
result:
ok 354 lines
Test #9:
score: 0
Accepted
time: 163ms
memory: 68716kb
input:
1000 1000 1 885017443 -749892693 154518370 2 438176645 -381379235 203717112 -20185 203717113 2 -319357718 243272333 5955 17731012 17731013 1 -189528781 -187395852 626788557 1 77060803 -520279482 -576199858 1 726484671 740876803 -575051510 1 -543269595 -568260043 -920010409 1 -310635724 133103122 691...
output:
558297999 251888865 749289813 103107045 678171550 479258991 711753936 16119490 259388891 395931607 68181127 801126955 548650181 2521730 261171772 417472150 127290066 95387785 711105356 592000401 548880329 717373606 183869602 456274805 31655345 874975006 636560035 473068238 345257911 16662590 5700368...
result:
ok 334 lines
Test #10:
score: 0
Accepted
time: 164ms
memory: 68688kb
input:
1000 1000 1 242203496 -23292191 306549544 2 509347373 -552518417 23255 270397512 270397513 2 203004566 -334228572 26913 362154784 362154785 1 -293078369 261961366 -470134545 1 -352559190 896968322 500066842 2 -245766163 -740888176 2723 -3707364 3707365 1 -975468755 -788213602 66881452 2 -152639966 6...
output:
669656423 307349535 244422176 105726054 391036902 519621062 895756478 856133490 294120648 477104600 592821343 41227900 220391171 29978795 80128698 575663178 31506736 270010322 410328448 324282140 580757610 606070008 363467911 157282937 329776212 734486276 25452970 717612884 726252783 195375372 97456...
result:
ok 360 lines
Subtask #3:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
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:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #16:
score: 0
Time Limit Exceeded
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:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
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:
Subtask #6:
score: 0
Skipped
Dependency #2:
100%
Accepted
Dependency #3:
0%