QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#786545#8717. 骰子KanateRE 0ms0kbC++172.0kb2024-11-26 21:58:452024-11-26 21:58:47

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 21:58:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-26 21:58:45]
  • 提交

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 add(ll &a,ll b){
    a = a + b >= mod ? a + b - mod : a + b;
}

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] = add(tmp[i+j] , a[i] * b[j] %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 = add(ANS ,ans[i-k] * sum[i] %mod);
        cout << ANS << endl;
        
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:


result: