QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#217849 | #6640. Talk That Talk | CharlieVinnie | WA | 1598ms | 18608kb | C++17 | 1.7kb | 2023-10-17 15:15:31 | 2023-10-17 15:15:32 |
Judging History
answer
#include "bits/stdc++.h"
#define DEBUG_OFF
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
#define range basic_string_view
using namespace std; typedef long long ll; constexpr __int128_t I=1;
void solve(){
ll p; int t; cin>>p>>t; if(p-1<t+t) return cout<<0<<'\n',void();
auto qpow=[&](ll x,ll y){
ll res=1; while(y) { if(y&1) res=I*res*x%p;; x=I*x*x%p; y>>=1; }; return res;
};
auto test=[&](ll x) { return x%p==0?0:qpow(x%p,(p-1)/2)==1?1:-1; };
ll ans=t*(p-3)+1;
vector<int> suf(t*2+1),pre(t*2+1); For(i,1,t*2) pre[i]=pre[i-1]+test(i),suf[i]=suf[i-1]+test(p-i);
for(int i=t*2,s0=0,s1=0;i>=0;i--){
swap(s0,s1); s0+=suf[t*2-i]-(i==t*2?0:suf[t*2-i-1]);
ans-=(pre[i]-(i==0?0:pre[i-1]))*s0+(t*2-i)/2+1; debug(i,ans);
}
// For(i,1,t) ans-=test(i)*test(p-i)+1;; debug(ans);
For(i,1,t){
ans-=(pre[i]-pre[i-1])*(suf[t-i]+pre[i+t]-pre[i*2-1]);
ans-=(suf[i]-suf[i-1])*(pre[t-i]+suf[i+t]-suf[i*2-1]);
}
debug(ans); assert(ans%4==0); cout<<ans/4<<'\n';
}
signed main(){
atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
int T; cin>>T; while(T--) solve();
return 0;
}
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// CONTINUE, NON-STOPPING, FOR CHARLIEVINNIE
// Started Coding On: October 16 Mon, 22 : 48 : 42
详细
Test #1:
score: 100
Accepted
time: 1222ms
memory: 18608kb
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: 223ms
memory: 3740kb
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: 291ms
memory: 3604kb
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: 1055ms
memory: 3664kb
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: 1261ms
memory: 3860kb
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: 1598ms
memory: 3668kb
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: -100
Wrong Answer
time: 242ms
memory: 3692kb
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 0 76 26 4 58 4 34 142 0 38 54 126 18 82 0 48 74 10 138 128 58 12 68 44 0 12 8 6 40 54 10 10 36 76 16 116 110 12 0 126 18 0 0 28 16 74 100 98 94 0 4 20 40 18 10 0 10 14 32 36 38 94 54 66 20 4 66 6 96 20 62 6 62 12 20 50 58 0 122 50 0 104 20 0 20 0 82 2 26 126 38 0 128 22 116 16 122 ...
result:
wrong answer 7th numbers differ - expected: '6', found: '0'