QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602708 | #8717. 骰子 | ucup-team902# | TL | 1ms | 5856kb | C++17 | 2.0kb | 2024-10-01 12:18:39 | 2024-10-01 12:18:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1500,M=200,Q=6e5;
const int mod=1e9+7;
int add(int x,int y){ return (x+=y)>=mod?x-mod:x; }
int sub(int x,int y){ return (x-=y)<0?x+mod:x; }
int n,m,qs;
int b[M+5];
int p[N+5][M+5];
struct Que{
int l,r,id;
Que(int l=0,int r=0,int id=0):l(l),r(r),id(id){}
};
int f[N+5][M+5];
int ans[Q+5];
void dp(int f[M+5],int g[M+5],int h[M+5]){
fill(h,h+m+1,0);
for(int i=0;i<=m;i++)
for(int j=0;i+j<=m;j++)
h[i+j]=(h[i+j]+1ll*f[i]*g[j])%mod;
}
void solve(int l,int r,vector<Que> &q){
if(l==r){
for(auto [l,r,i]:q){
for(int j=0;j<=m;j++)
ans[i]=(ans[i]+1ll*p[l][j]*b[j])%mod;
}
return;
}
int mid=l+r>>1;
for(int i=0;i<=m;i++) f[mid][i]=p[mid][i];
for(int i=0;i<=m;i++) f[mid+1][i]=p[mid+1][i];
for(int i=mid-1;i>=l;i--)
dp(f[i+1],p[i],f[i]);
for(int i=mid+2;i<=r;i++)
dp(f[i-1],p[i],f[i]);
static int h[M+5];
for(int i=1;i<=mid;i++){
memset(h,0,sizeof h);
for(int j=0;j<=m;j++)
for(int k=j;k<=m;k++)
h[k-j]=(h[k-j]+1ll*f[i][j]*b[k])%mod;
for(int j=0;j<=m;j++) f[i][j]=h[j];
}
vector<Que> ql,qr;
for(auto it:q){
auto [l,r,i]=it;
if(r<=mid) ql.push_back(it);
else if(l>mid) qr.push_back(it);
else{
int *vl=f[l],*vr=f[r];
for(int j=0;j<=m;j++)
ans[i]=(ans[i]+1ll*vl[j]*vr[j])%mod;
}
}
solve(l,mid,ql);
solve(mid+1,r,qr);
}
int main(){
scanf("%d %d %d",&n,&m,&qs);
for(int i=0;i<=m;i++)
scanf("%d",&b[i]);
for(int i=1;i<=n;i++)
for(int j=0;j<=m;j++)
scanf("%d",&p[i][j]);
vector<Que> q;
for(int i=1;i<=qs;i++){
int l,r;
scanf("%d %d",&l,&r);
q.push_back({l,r,i});
}
solve(1,n,q);
for(int i=1;i<=qs;i++)
printf("%d\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5816kb
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: 5856kb
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: 3780kb
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...