QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#786534 | #8717. 骰子 | Kanate | TL | 1ms | 3668kb | C++17 | 1.9kb | 2024-11-26 21:56:11 | 2024-11-26 21:56:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7 ;
const int N = 1505;
const int M = 205;
int n , m , q;
ll t[N][205];
ll *r[N];
int cnt[N];
ll ans[205];
ll qpow(ll a,ll b){
ll ans = 1;
for(;b;b>>=1,a=a*a%mod) if(b&1) ans = ans * a %mod;
return ans;
}
ll* inv(int n,ll *a){
ll *b;
b = (ll*)malloc(sizeof(ll)*M);
memset(b,0,sizeof(ll)*M);
ll inv = qpow(a[0],mod-2);
b[0] = inv;
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++)
b[i] = (b[i] - a[j]*b[i-j]%mod + mod) % mod;
b[i] = b[i] * inv % mod;
}
return b;
}
ll tmp[M],sum[N];
void mul(ll *a,ll *b){
memset(tmp,0,sizeof tmp);
for(int i=0;i<=200;i++)
for(int j=0;j<=200-i;j++)
tmp[i+j] = (tmp[i+j] + a[i] * b[j] %mod) % mod;
for(int i=0;i<=200;i++) a[i] = tmp[i];
}
/*
3 3 3
4 3 2 1
0 1 0 1000000007
0 500000004 0 500000004
0 0 500000004 500000004
1 1
1 2
1 3
*/
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> m >> q;
t[0][0] = 1;
for(int i=0;i<=m;i++) cin >> sum[i];
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++) cin >> t[i][j];
while(cnt[i]<=m){
if((t[i][cnt[i]]%=mod)!=0) break;
cnt[i]++;
}
for(int j=0;j<=m-cnt[i];j++)
t[i][j] = t[i][j+cnt[i]];
for(int j=m-cnt[i]+1;j<=m;j++)
t[i][j] = 0 ;
if(cnt[i] == m+1) t[i][0] = 1;
if(i!=1)mul(t[i],t[i-1]);
r[i] = inv(200,t[i]);
cnt[i] += cnt[i-1];
}
while(q-->0){
int L,R ;
cin >> L >> R;
for(int i=0;i<=m;i++) ans[i] = t[R][i];
int k = cnt[R] - cnt[L-1];
if(L!=1) mul(ans,r[L-1]);
ll ANS = 0 ;
for(int i=k;i<=m;i++)
ANS =(ANS + ans[i-k] * sum[i] %mod) %mod;
cout << ANS << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
3 3 3 4 3 2 1 0 1 0 1000000007 0 500000004 0 500000004 0 0 500000004 500000004 1 1 1 2 1 3
output:
3 1 0
result:
ok 3 number(s): "3 1 0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
3 3 6 4 3 2 1 1000000007 0 1 0 1000000007 1 0 0 1000000007 0 1 0 1 1 1 2 1 3 2 2 2 3 3 3
output:
2 1 0 3 1 2
result:
ok 6 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 1 1 604063100 57375033 742299910 257700098 1 1
output:
148903503
result:
ok 1 number(s): "148903503"
Test #4:
score: -100
Time Limit Exceeded
input:
1500 200 600000 253665324 876103781 804024983 929290295 908790466 176299158 528078340 696679927 416465140 509641654 705083449 361711737 250659645 735832780 35321360 383752049 203979021 178832532 785212637 514502839 169840231 65809146 504755349 516829442 382478309 901925498 142312128 782336477 741339...
output:
66394849 858043015 290088512 433850735 16359498 544692508 495705795 390858705 334940115 441003348 589429674 891250455 147055038 949270774 782296292 854444995 608076278 772991067 609961969 3444634 534397763 659524291 384815421 329963211 259265811 214554716 662015873 465616975 355211926 398786302 7484...