QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#402009 | #6640. Talk That Talk | Nahidameow | TL | 1984ms | 49616kb | C++20 | 1.9kb | 2024-04-29 19:00:48 | 2024-04-29 19:00:50 |
Judging History
answer
#include<bits/stdc++.h>
#define pd push_back
#define all(A) A.begin(),A.end()
#define lb lower_bound
#define ve std::vector
typedef long long ll;
typedef long long ll;
typedef __int128 Int;
typedef unsigned long long ul;
typedef long double LD;
bool FileIfstream(std::string name){
std::ifstream f(name.c_str());
return f.good();
}
namespace Math{
ll QP(Int x,ll y,ll mod){ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ans=x*ans%mod;return ans;}
ll inv(ll x,ll mod){return QP(x,mod-2,mod);}
}
const int N=2e5+10;
ll mod;
ll Ler(ll x,ll mod){
ll p=Math::QP(x,(mod-1)/2,mod);
return p<=1?p:-1;
}
void solve(){
//don't forget to open long long
ll t;std::cin>>mod>>t;t=std::min(1ll*t,(mod-1)/2);
ll S=0;
ve<int>val(4*t+1);
for(int i=0;i<=t*4;i++)
val[i]=Ler(i+mod-2*t,mod);
// for(int i=0;i<=t*4;i++)
// std::cout<<val[i]<<' ';std::cout<<'\n';
ve<int>S1(4*t+1),S2(4*t+1);
for(int i=0;i<=t*4;i++){
S1[i]=val[i];S2[i]=val[i];
if(i)S1[i]+=S1[i-1];
if(i>1)S2[i]+=S2[i-2];
}ll ans=0;
for(int i=1;i<=t;i++)
ans+=mod-4-Ler(i,mod)*Ler(i*2,mod);
/*for(int i=1;i<=(mod-1)/2;i++){
int res=0;
for(int j=0;j<mod;j++)
res+=1+Ler(j,mod)*Ler(j-i,mod)+Ler(j,mod)*Ler(j+i,mod)+Ler(j-i,mod)*Ler(j+i,mod);
std::cerr<<res<<'\n';
}*/
for(int i=0;i<t*2;i++){
ll L=(t*2-i+1)/2;
ans-=(t-L+1)+val[i]*(S1[i+t]-S1[i+L-1]+S2[i+t*2]-S2[i+(L-1)*2]);
}
for(int i=0;i<t*4;i++){
ll L=std::max({i-t*2+1,t*2-i,1ll});
ll R=std::min({t*4-1-i,t,1ll*i});
if(L<=R)ans-=val[i]*(S1[i+R]-S1[i+L-1]);
}
// ans-=3*t+2*Ler(2,mod)*t+Ler(-1,mod)*t;
std::cout<<ans/4<<'\n';
}
int main(){
#ifndef ONLINE_JUDGE
if(!FileIfstream("IO.in")){
freopen("IO.in","w",stdout);
return 0;
}
freopen("IO.in","r",stdin);
freopen("IO.out","w",stdout);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int T=1;
std::cin>>T;
while(T--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1984ms
memory: 49616kb
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: 367ms
memory: 3900kb
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: 188ms
memory: 3624kb
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: 1298ms
memory: 3632kb
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: 1646ms
memory: 3568kb
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: -100
Time Limit Exceeded
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...