QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#669327 | #8339. Rooted Tree | huan_yp# | AC ✓ | 1120ms | 82248kb | C++20 | 2.1kb | 2024-10-23 18:11:35 | 2024-10-23 18:11:36 |
Judging History
answer
#include<bits/stdc++.h>
#define mod 1000000009u
using namespace std;
long long m,k;
int ima[10000007], imb[10000007];
struct barrett{
unsigned long long im;int m;
barrett(unsigned m) :m(m), im(~0ull/m+1) {}
inline int operator ()(int a,int b){
unsigned long long z=(unsigned long long)a*b;
int v = z - ((__int128)z * im >> 64) * m;
return v<0?v+m:v;
}
}bt(1);
array<int, 4> mi_vec(vector<int> a, int b=mod-2){
array<int, 4> ans({1,1,1,1});
while(b){
if(b&1){
ans[0] = bt(ans[0], a[0]);
ans[1] = bt(ans[1], a[1]);
ans[2] = bt(ans[2], a[2]);
ans[3] = bt(ans[3], a[3]);
// ans[0]=1ll*ans[0]*a[0]%mod;
// ans[1]=1ll*ans[1]*a[1]%mod;
// ans[2]=1ll*ans[2]*a[2]%mod;
// ans[3]=1ll*ans[3]*a[3]%mod;
}
b>>=1;
a[0] = bt(a[0], a[0]);
a[1] = bt(a[1], a[1]);
a[2] = bt(a[2], a[2]);
a[3] = bt(a[3], a[3]);
}
// cerr << "T:\n";
return ans;
}
int mi(int a,int b=mod-2){
// return 1;
int ans=1;
while(b){
if(b&1) ans=1ll*ans*a%mod;
b>>=1;a=1ll*a*a%mod;
}
return ans;
}
int main(){
scanf("%lld%lld",&m,&k);
bt = barrett(mod);
double start = clock();
long long nw=0,lf=0;
int i=1;
for(i=1;i+4<k;i+=4){
// cerr << "W:" << '\n';
memcpy(ima + i, mi_vec({
(i + 0) * m + 1,
(i + 1) * m + 1,
(i + 2) * m + 1,
(i + 3) * m + 1,
}).data(), 4 * 4);
memcpy(imb + i, mi_vec({
1 + (i + 0) * (m - 1),
1 + (i + 1) * (m - 1),
1 + (i + 2) * (m - 1),
1 + (i + 3) * (m - 1),
}).data(), 4 * 4);
}
for(;i<=k;i++){
ima[i] = mi(i * m + 1);
imb[i] = mi(1 + i * (m - 1));
}
for(int i=1;i<=k;++i){
nw=(1ll*(lf+1)*m+1ll*nw*(1+(i-1)*m))%mod* ima[i] %mod;
lf+=1ll*m* imb[i] %mod;lf%=mod;
}
nw=nw*(1+1ll*k*m)%mod;
printf("%lld\n",nw);
cerr << "time:" << clock() - start << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5988kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 6140kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 70ms
memory: 11036kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 745ms
memory: 59488kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5884kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 790ms
memory: 63592kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 448ms
memory: 38476kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 1096ms
memory: 81700kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 203ms
memory: 22928kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 602ms
memory: 48180kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 356ms
memory: 34864kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 319ms
memory: 31140kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 949ms
memory: 72848kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 1107ms
memory: 82092kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 1120ms
memory: 82248kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 1109ms
memory: 82016kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed