QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#190490 | #6640. Talk That Talk | Crysfly | AC ✓ | 829ms | 66168kb | C++20 | 2.9kb | 2023-09-28 23:11:27 | 2023-09-28 23:11:27 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 4000015
#define inf 0x3f3f3f3f
ll p,res;
int t;
long double iP;
ll mul(ll x,ll y){
ll d=x*iP*y+0.5,s=x*y-d*p;
return s+((s>>63)&p);
}
ll qpow(ll a,ll b){
ll c=1;
for(;b;b>>=1,a=mul(a,a))if(b&1)c=mul(c,a);
return c;
}
int A[maxn],SA[maxn],*a=A+2000003,*sa=SA+2000003;
void work()
{
p=read(),t=read(),iP=1.0l/p;
t=min(t,p/2-1),res=0;
int n=t*2;
// n=p-1;
n=min(n,p-1);
Rep(i,n,-n){
if(i<=0)a[i]=(p%4==3?-a[-i]:a[-i]);
else a[i]=(qpow(i,(p-1)/2)==1)?1:-1;
}
a[-n-1]=sa[-n-1]=0;
For(i,-n,n)sa[i]=sa[i-1]+a[i];
// For(d,1,t){
// int sum=0,sum2=0;
// For(i,0,p-1){
// int now=a[i]*a[(i+d)%p]+(a[(i+d)%p]*a[(i+d*2)%p])+(a[i]*a[(i+2*d)%p]);
// now+=1;
//// cerr<<"now "<<now<<"\n";
// sum+=a[i]*a[(i+d)%p],sum+=(a[(i+d)%p]*a[(i+d*2)%p]),sum2+=(a[i]*a[(i+2*d)%p]);
// }
// // sum=sum*2+sum2;
// sum+=sum2;
// sum+=p;
// cout<<sum<<"\n";
// // sum-=(a[d]*a[(p-d)%p]+1);
// // cout<<"S "<<sum<<"\n";
// res+=sum;
// }
res+=(p-3)*t;
res-=t*(t+1);
//For(d,1,t) res-=d*2;
// cout<<"RES "<<res<<"\n";
// For(d,1,t){
// // res-=d*2;
// For(i,0,p-1){
// if(i+d*2>=p){
// int now=a[i]*a[(i+d)%p]+(a[(i+d)%p]*a[(i+d*2)%p])+(a[i]*a[(i+2*d)%p]);
// // cout<<"Sub "<<now<<"\n";
// res-=now;
// }
// }
// }
auto pres=[&](int l,int r){
assert(r<=n);
assert(l>=-n);
return sa[r]-sa[l-1];
};
res-=t;
// cerr<<"Res "<<res<<"\n";
For(i,-2*t,-1){
int j=(-i+1)/2;
// cout<<"i,j "<<i<<" "<<j<<"\n";
res-=a[i]*pres(i+j,i+t);
}
For(i,1,t){
res-=a[i]*pres(i+i,i+t);
}
// cout<<"qwq "<<res<<"\n";
For(i,0,t-1)
res-=a[i-t]*pres(0,i);
// cout<<"qwq2 "<<res<<"\n";
sa[-n-1]=sa[-n-2]=0;
For(i,-n,n){
sa[i]=a[i];
if(i-2>=-n) sa[i]+=sa[i-2];
}
For(i,-2*t,-1){
int j=(-i+1)/2;
// cout<<"i,j "<<i<<" "<<j<<" "<<a[i]<<" "<<sa[i+2*t]<<" "<<sa[i+2*(j-1)]<<"\n";
res-=a[i]*(sa[i+2*t]-sa[i+2*(j-1)]);
// cout<<"ovo "<<a[i]*(sa[i+2*t]-sa[i+2*(j-1)])<<"\n";
//cout<<"res: "<<res<<"\n";
}
// cerr<<"res "<<res<<"\n";
res/=4;
// cout<<res<<"\n";
printf("%lld\n",res);
}
signed main()
{
int T=read();
while(T--)work();
return 0;
}
/*
7
7 32
13 1
13 2
67 11
2003 44
1000003 1984
999999999989 987654
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 770ms
memory: 65900kb
input:
7 7 32 13 1 13 2 67 11 2003 44 1000003 1984 999999999989 987654
output:
0 2 2 146 21510 495014784 246913256130162788
result:
ok 7 numbers
Test #2:
score: 0
Accepted
time: 119ms
memory: 7608kb
input:
11696 5 1 5 2 7 1 7 2 7 3 11 1 11 2 11 3 11 4 11 5 13 1 13 2 13 3 13 4 13 5 13 6 17 1 17 2 17 3 17 4 17 5 17 6 17 7 17 8 19 1 19 2 19 3 19 4 19 5 19 6 19 7 19 8 19 9 23 1 23 2 23 3 23 4 23 5 23 6 23 7 23 8 23 9 23 10 23 11 29 1 29 2 29 3 29 4 29 5 29 6 29 7 29 8 29 9 29 10 29 11 29 12 29 13 29 14 31...
output:
0 0 0 0 0 2 4 4 6 6 2 2 4 4 4 4 2 4 4 6 6 6 8 8 4 8 10 12 16 18 18 20 20 4 8 12 16 20 22 24 24 24 24 24 6 12 18 24 24 28 32 36 40 40 40 44 44 44 6 12 18 22 26 32 34 36 42 44 44 46 46 46 46 8 14 22 26 32 38 42 44 52 54 56 60 62 62 64 64 64 64 8 16 20 28 34 38 44 52 54 56 60 64 66 68 70 74 74 74 76 76...
result:
ok 11696 numbers
Test #3:
score: 0
Accepted
time: 67ms
memory: 7728kb
input:
500000 71 1 41 1 67 1 17 1 29 1 97 1 11 1 59 1 89 1 71 1 7 1 31 1 71 1 13 1 67 1 97 1 13 1 37 1 29 1 13 1 67 1 37 1 97 1 59 1 89 1 83 1 73 1 29 1 13 1 89 1 17 1 43 1 31 1 37 1 79 1 41 1 23 1 83 1 7 1 19 1 11 1 67 1 73 1 71 1 67 1 17 1 47 1 17 1 29 1 41 1 97 1 13 1 47 1 43 1 23 1 7 1 73 1 13 1 47 1 7...
output:
16 8 16 2 6 22 2 14 20 16 0 6 16 2 16 22 2 8 6 2 16 8 22 14 20 20 16 6 2 20 2 10 6 8 18 8 4 20 0 4 2 16 16 16 16 2 10 2 6 8 22 2 10 10 4 0 16 2 10 0 2 20 6 8 14 16 16 2 14 12 2 8 16 0 16 0 18 2 2 4 16 14 16 2 2 22 14 20 20 10 16 16 22 14 16 14 18 0 20 6 2 16 10 4 14 2 22 4 20 2 18 0 6 20 2 4 14 0 12...
result:
ok 500000 numbers
Test #4:
score: 0
Accepted
time: 446ms
memory: 7956kb
input:
500000 796985057191 1 567957900049 1 827610855103 1 919580142883 1 705957627181 1 854537570797 1 653636687779 1 516224177893 1 616020013397 1 518523794483 1 904311938423 1 534402190409 1 578460069899 1 754072383349 1 556038395257 1 676067642057 1 759949674839 1 913727773951 1 792376257731 1 51332043...
output:
199246264296 141989475010 206902713774 229895035720 176489406794 213634392698 163409171944 129056044472 154005003348 129630948620 226077984604 133600547600 144615017474 188518095836 139009598812 169016910512 189987418708 228431943486 198094064432 128330108024 213838430616 148581110810 138371413484 1...
result:
ok 500000 numbers
Test #5:
score: 0
Accepted
time: 580ms
memory: 7652kb
input:
500000 4630931 1 532378711517 2 897492424691 1 933429720763 2 50396453 1 965938979207 1 757130529707 1 585648391093 2 93206693 1 582531600551 1 902156055859 1 673348731047 1 43627163 2 786341452943 1 630094950481 2 500747394781 2 55003589 2 662875627321 2 554939202737 2 729610579949 1 48444437 2 644...
output:
1157732 266189355756 224373106172 466714860380 12599112 241484744800 189282632426 292824195542 23301672 145632900136 225539013964 168337182760 21813580 196585363234 315047475234 250373697386 27501792 331437813654 277469601364 182402644986 24222216 161182653834 403691568340 409143875612 24208052 1779...
result:
ok 500000 numbers
Test #6:
score: 0
Accepted
time: 829ms
memory: 7724kb
input:
500000 999999769291 2 999999916099 2 999999337661 2 999999619897 2 999999711979 2 999999125599 2 999999617677 2 999999902791 2 999999704749 2 999999640721 2 999999284629 2 999999430669 2 999999876917 2 999999555559 2 999999545273 2 999999426997 2 999999814963 2 999999272717 2 999999621109 2 99999955...
output:
499999884644 499999958048 499999668828 499999809942 499999855988 499999562796 499999808834 499999951392 499999852370 499999820356 499999642310 499999715330 499999938456 499999777776 499999772632 499999713494 499999907480 499999636356 499999810550 499999775204 499999646592 499999695462 499999792794 4...
result:
ok 500000 numbers
Test #7:
score: 0
Accepted
time: 73ms
memory: 7768kb
input:
182082 73 3 11 5 83 3 71 8 67 1 97 3 11 8 89 4 37 4 23 1 43 7 13 5 41 5 71 9 7 6 41 6 59 4 89 7 29 3 53 8 13 9 53 4 53 7 43 1 67 10 73 10 67 4 31 2 79 4 43 5 11 10 29 2 37 1 17 6 89 2 79 3 47 1 47 1 53 3 43 10 67 1 97 6 83 6 31 2 7 8 89 7 19 6 5 9 17 10 59 2 19 5 61 6 67 7 97 5 89 5 5 3 13 3 83 1 29...
output:
44 6 56 126 16 62 6 76 26 4 58 4 34 142 0 38 54 126 18 82 4 48 74 10 138 128 58 12 68 44 6 12 8 6 40 54 10 10 36 76 16 116 110 12 0 126 18 0 8 28 16 74 100 98 94 0 4 20 40 18 10 4 10 14 32 36 38 94 54 66 20 4 66 6 96 20 62 6 62 12 20 50 58 0 122 50 6 104 20 4 20 0 82 2 26 126 38 0 128 22 116 16 122 ...
result:
ok 182082 numbers
Test #8:
score: 0
Accepted
time: 782ms
memory: 7840kb
input:
181367 625226585029 1 546867924943 3 953697022237 9 546332273987 5 701504204207 5 667670881783 9 510105485471 2 766942437293 2 690753416891 9 723074805317 2 701991568721 7 507206403259 4 511745218031 2 520493347639 9 705498928573 10 647261678981 6 954299288291 1 865750160161 7 848125626919 8 6695742...
output:
156306646256 410150943702 2145818300002 682915342476 876880255250 1502259483980 255052742732 383471218644 1554195187986 361537402656 1228485245230 507206403252 255872609012 1171110032160 1763747321400 970892518454 238574822072 1515062780234 1696251253806 1506542157808 152874865660 379612385868 33052...
result:
ok 181367 numbers
Test #9:
score: 0
Accepted
time: 712ms
memory: 7728kb
input:
181864 96073657 1 802537045631 9 624461538209 9 641739372587 7 94372547 4 562283886301 10 986572793593 2 912998339921 10 78529733 6 762028834409 8 857265814973 2 852255337621 6 92213951 10 660819443131 3 552549324851 2 837226333271 2 2721421 9 623159788477 4 850163710043 6 779567606201 3 23673379 6 ...
output:
24018412 1805708352654 1405038460930 1123043902010 94372540 1405709715704 493286396790 2282495849754 117794586 1524057668788 428632907484 1278383006410 230534858 495614582344 276274662424 418613166632 6123164 623159788466 1275245565050 584675704640 35510056 1878626615510 898299738454 1246361224308 1...
result:
ok 181864 numbers
Test #10:
score: 0
Accepted
time: 800ms
memory: 7664kb
input:
181572 999999412481 9 999999477089 7 999999070423 9 999999904439 3 999999474869 6 999999713329 8 999999378673 6 999999955709 5 999999203807 7 999999752107 3 999999750929 6 999999738019 4 999999033937 4 999999848293 8 999999390001 6 999999565897 7 999999067757 7 999999829553 6 999999229199 4 99999905...
output:
2249998678040 1749999084876 2249997908420 749999928324 1499999212288 1999999426588 1499999067976 1249999944622 1749998606648 749999814074 1499999626366 999999738010 999999033920 1999999696564 1499999084966 1749999240286 1749998368556 1499999744310 999999229192 1499998578510 1499999669604 19999997184...
result:
ok 181572 numbers
Test #11:
score: 0
Accepted
time: 4ms
memory: 7948kb
input:
2011 7 471 13 438 71 450 73 503 11 431 41 332 17 439 79 301 19 573 53 639 41 573 97 323 41 681 37 647 79 671 31 381 7 573 23 330 83 413 83 627 61 356 23 499 29 645 79 302 43 407 11 544 79 367 29 676 11 584 11 343 13 494 37 385 29 673 37 396 59 555 67 507 37 518 7 594 59 330 79 691 29 401 17 567 7 50...
output:
0 4 304 284 6 76 8 346 20 160 76 528 76 64 346 46 0 24 412 412 204 24 44 346 102 6 346 44 6 6 4 64 44 64 218 256 64 0 218 346 44 8 0 44 346 46 528 102 528 122 428 0 44 76 304 160 256 46 6 218 4 76 428 428 46 204 0 4 412 428 44 46 46 46 0 8 204 346 304 284 218 76 256 160 256 0 4 428 64 76 20 204 4 44...
result:
ok 2011 numbers
Test #12:
score: 0
Accepted
time: 761ms
memory: 7704kb
input:
1990 637503428677 440 549004707871 541 769745081489 695 879093250957 605 611329620529 652 864211918343 666 700791036773 349 850753783819 535 932257508641 300 985130811229 642 874333565569 392 615973720897 490 925773806137 591 719331117991 439 769555585171 649 847102210267 458 658159634039 383 900121...
output:
70125377105496 74252886666334 133743207786678 132962854114850 99646728038282 143891284293240 61144017927718 113788318513656 69919313117130 158113495098766 85684689384592 75456780748950 136783079767306 78946590150896 124860393587860 96993203022690 63018784930098 110264832212732 163656960936460 814107...
result:
ok 1990 numbers
Test #13:
score: 0
Accepted
time: 683ms
memory: 7840kb
input:
2008 37067759 665 997706855857 421 873137128477 574 622158050639 520 88965103 481 824624568587 325 746989568293 699 899174850389 657 95088403 568 588674377667 313 998841897227 489 683237363819 496 42812989 378 911280507173 580 810962042663 458 828206107847 343 66396221 455 712089656231 634 853410221...
output:
6162403114 105008646532330 125295177853110 80880546520240 10697995142 67000746170764 130536426936320 147689469067352 13502471902 46063770027660 122108421875658 84721433055518 4045789976 132135673455522 92855153832446 71018673718992 7552517926 112866210413454 65285881929922 170039581786022 1350042154...
result:
ok 2008 numbers
Test #14:
score: 0
Accepted
time: 775ms
memory: 7652kb
input:
2010 999999309887 634 999999286501 333 999999180329 463 999999721921 615 999999149251 313 999999853451 304 999999426053 531 999999318667 626 999999682133 464 999999781051 326 999999901759 632 999999138221 575 999999375383 656 999999018511 423 999999660827 412 999999679697 424 999999092647 500 999999...
output:
158499890515992 83249940573174 115749905069020 153749957145426 78249933404132 75999988838844 132749923737502 156499893272580 115999963072994 81499982128920 157999984377590 143749876036130 163999897455460 105749896162654 102999965022600 105999966001950 124999886517730 173749838494766 158499864580304 ...
result:
ok 2010 numbers
Test #15:
score: 0
Accepted
time: 1ms
memory: 7612kb
input:
100 19 10256 43 9026 31 10423 73 9620 13 10093 79 10381 67 9662 43 9797 83 10140 67 9871 53 9216 53 9107 41 10325 31 10086 31 10781 41 9944 79 9163 37 10208 7 9778 43 10157 43 10185 61 10448 67 10751 37 9947 89 9049 79 9567 59 10796 71 9283 5 9306 59 9369 97 9275 5 9230 23 9726 67 9354 11 10430 17 9...
output:
20 102 46 284 4 346 256 102 412 256 160 160 76 46 46 76 346 64 0 102 102 204 256 64 428 346 218 304 0 218 528 0 24 256 6 8 64 160 4 6 304 6 44 6 8 0 46 76 160 0 6 528 6 76 528 46 4 122 64 24 412 256 160 284 428 412 46 0 346 218 412 428 76 76 304 46 76 122 160 284 20 304 428 204 6 4 428 346 122 76 8 ...
result:
ok 100 numbers
Test #16:
score: 0
Accepted
time: 754ms
memory: 7608kb
input:
99 837315702089 9318 742374151357 10094 740840788559 10929 568368745229 10385 825135734509 10357 956685244061 10196 507072573797 10544 982627709341 10591 713147778787 10042 888149520173 9474 899919414971 9744 501171020969 10982 601135101293 10130 987974989147 9512 548068782361 10235 528327518347 106...
output:
1950526906289312 1873381145465826 2024162214677174 1475627327831124 2136482673729052 2438590661103730 1336643276724390 2601752489301378 1790357473423364 2103582116078956 2192203671147810 1375965007901068 1522374618358432 2349404501565580 1402370970444086 1407332398607020 1851756556673614 15148228256...
result:
ok 99 numbers
Test #17:
score: 0
Accepted
time: 680ms
memory: 7952kb
input:
100 91998043 10152 879778234633 9812 800889095533 10286 576190576349 10935 82187477 9188 985378110337 9130 666488218141 10549 886993073311 10370 12299291 9148 924809757733 10359 957294310481 9048 999186537053 10301 14306651 10234 770161755599 9915 991900668119 10216 677394473333 9851 32374597 10017 ...
output:
233465255698 2158095985396262 2059486282685864 1575160958190762 188763521804 2249125515884350 1757696025460266 2299529515659056 28107554936 2395026043238452 2165399709815742 2573155103010216 36577397672 1909038427198584 2533314280268352 1668253214930594 81048985670 1891299897534418 1624606312444994 ...
result:
ok 100 numbers
Test #18:
score: 0
Accepted
time: 784ms
memory: 10000kb
input:
99 999999268259 9214 999999943699 10718 999999685541 9099 999999763283 10512 999999817571 10083 999999330683 9023 999999692759 9903 999999728249 10492 999999839093 10659 999999375911 10679 999999725111 10049 999999662693 9059 999999599593 10052 999999137617 9756 999999109673 10213 999999160673 10239...
output:
2303498293221744 2679499820414282 2274749263975026 2627999350281822 2520749514734104 2255748469825378 2475749214870964 2622999259634288 2664749542805060 2669748305315522 2512249284218164 2264749215556486 2512998968500938 2438997872844218 2553247700668536 2559747825306160 2694497689619794 25057484152...
result:
ok 99 numbers
Test #19:
score: 0
Accepted
time: 469ms
memory: 66168kb
input:
1 36283549 1000000
output:
8820884420630
result:
ok 1 number(s): "8820884420630"
Test #20:
score: 0
Accepted
time: 772ms
memory: 66124kb
input:
1 999999324481 1000000
output:
249999581112252902
result:
ok 1 number(s): "249999581112252902"