QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#631926 | #9451. Expected Waiting Time | ucup-team4863# | WA | 301ms | 30708kb | C++14 | 1.9kb | 2024-10-12 11:02:37 | 2024-10-12 11:02:38 |
Judging History
answer
// created: 2024-10-12 08:55:42
#include<cstdio>
#include<cctype>
#include<algorithm>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
#define I128 //||is_same<T,__int128_t>::value||is_same<T,__uint128_t>::value
using namespace std;
template<typename T>enable_if_t<is_integral<T>::value I128,void> readmain(T &x)
{
bool neg=false;int c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')neg=true;
for(x=0;isdigit(c);c=getchar())x=(T)(10*x+(c-'0'));
if(neg)x=-x;
}
template<typename T>T& read(T &x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &x,Tr&... r){readmain(x);read(r...);}
typedef __uint128_t u128;
typedef unsigned long long ull;
constexpr int N=2e6+5;int mod;
void reduce(int &x){if(x>=mod)x-=mod;}
struct barrett
{
ull mod,inv;
void init(int mod_){mod=mod_;inv=(-1ull)/mod+1ull;}
int operator()(ull x)
{
x-=(ull)((u128)x*inv>>64)*mod;
if(x>>63)x+=mod;
return (int)x;
}
}bar;
int qpow(int a,int b,int c=1)
{
for(;b;b>>=1,a=bar((ull)a*a))if(b&1)c=bar((ull)c*a);
return c;
}
int fac[N],invfac[N];
int n,a[N],cat[N];
void gen()
{
int b0,ca,cb,sa=0;
read(b0,ca,cb);
F(i,0,n)
{
b0=bar((ull)ca*b0+cb);
reduce(sa+=b0+1);
a[i]=sa;
}
}
void initfac()
{
F(i,fac[0]=1,n+1)fac[i]=bar((ull)fac[i-1]*i);
invfac[n]=qpow(fac[n],mod-2);
for(int i=n;i;--i)invfac[i-1]=bar((ull)invfac[i]*i);
}
void solve()
{
read(n,mod);
bar.init(mod);
n<<=1;
gen();initfac();
n>>=1;
F(i,0,n+1)cat[i]=bar((ull)bar((ull)fac[2*i]*invfac[i])*invfac[i+1]);
int ans=0,tot=cat[n];
int ho=tot;
F(i,0,n)
{
if(i&1)ho=bar(ho+(ull)(mod-cat[i>>1])*cat[n-1-(i>>1)]);
ans=bar(ans+(tot+2ull*(mod-ho))*(a[i]+mod-a[2*n-1-i]));
}
ans=bar((ull)ans*invfac[2*n]);
ans=bar((ull)ans*fac[n]);ans=bar((ull)ans*fac[n+1]);
printf("%d\n",ans);
}
int main()
{
int tt;
read(tt);
while(tt--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7656kb
input:
5 1 1000000007 0 1 0 2 1000000007 0 1 1 2 7 5 2 3 3 31 15 6 24 20 1000000007 0 1 0
output:
1 12 1 21 879705565
result:
ok 5 number(s): "1 12 1 21 879705565"
Test #2:
score: 0
Accepted
time: 293ms
memory: 7632kb
input:
4400 3954 1000000007 0 1 0 1306 1000000007 0 1 0 3774 1000000007 0 1 0 3345 1000000007 0 1 0 891 1000000007 0 1 0 2462 1000000007 0 1 0 237 1000000007 0 1 0 26 1000000007 0 1 0 2510 1000000007 0 1 0 637 1000000007 0 1 0 3250 1000000007 0 1 0 3447 1000000007 0 1 0 1222 1000000007 0 1 0 133 1000000007...
output:
440618338 378292891 979368645 915766295 343598158 80867595 161627927 517387931 396936703 42785642 945720545 764273281 186237656 635777911 164064906 548455037 991964184 468137124 561243246 118562285 856945294 642467240 23673926 808943705 897417615 462422554 656411244 204288121 997894281 244685651 762...
result:
ok 4400 numbers
Test #3:
score: -100
Wrong Answer
time: 301ms
memory: 30708kb
input:
1019 338 1863833207 1820742817 1507924477 1822273457 770 1386304741 1088481071 1216187083 170973217 597 1604266739 620750027 196415899 456280997 105 1008587891 184044403 24836083 926135599 357 1165127407 440925347 1103369747 912263123 82 1639766993 263045351 631010551 1412721139 928 1715915153 25383...
output:
373412135 909478089 988735502 827110887 310057771 105970079 1592944624 17236634 1167212295 521144008 1009499206 580644886 405149419 1559150541 500656729 29114938 470634881 322958100 441888172 835750076 747526883 1671785296 1089271112 894559715 558752169 1050819260 65894588 844160548 966608592 478142...
result:
wrong answer 1st numbers differ - expected: '1532578211', found: '373412135'