QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#603091 | #8717. 骰子 | Komorebie# | TL | 2ms | 9880kb | C++17 | 2.7kb | 2024-10-01 14:40:01 | 2024-10-01 14:40:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define maxn 600050
#define ll long long
ll qsize;
const int mod = 1e9+7;
struct node{
int l,r,id;
bool operator <(const node x)const{
if(l/qsize==x.l/qsize)return r<x.r;
else return l<x.l;
}
bool operator >(const node x)const{
if(l/qsize==x.l/qsize)return r>x.r;
else return l>x.l;
}
}a[maxn];
ll n,m,q,b[300],c[1600][205],sum[205],ans[maxn],tmp[maxn];
void solve(ll *a,ll *b){
for(int i=m;i>=0;i--){
a[i]*=b[0];
a[i]%=mod;
for(int j=1;j<=i;j++){
a[i]+=a[i-j]*b[j];
}
}
}
ll check(int x){
ll sum[205],ans=0;
for(int i=0;i<=m;i++)sum[i]=c[a[x].l][i];
for(int i=a[x].l+1;i<=a[x].r;i++){
solve(sum,c[i]);
}
for(int i=0;i<=m;i++){
ans+=(sum[i]*b[i])%mod;
ans%=mod;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>q;
qsize=sqrt(n);//分块
for(int i=0;i<=m;i++){
cin>>b[i];
}
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++){
cin>>c[i][j];
}
}
for(int i=1;i<=q;i++){
cin>>a[i].l>>a[i].r;
a[i].id=i;
}
sort(a+1,a+q+1);
int last=-n,l,r,ls;//last存储的是上一个处理的 l,ls是l的copy
for(int i=1;i<=q;i++){
if (a[i].l / qsize == a[i].r / qsize)
{
ans[a[i].id]=check(i);
ans[a[i].id]%=mod;
continue;
}//如果位于同一块,直接处理
if(a[i].l/qsize!=last/qsize){
l=a[i].r+1,r=a[i].r;
memset(sum,0,sizeof(sum));
}//如果此时的处理的区间的l跟上一次处理的不一样,重新初始化
last=a[i].l;
while(a[i].r>r){
if(l>r){//如果为空莫队的话,直接赋值
r++;
for(int j=0;j<=m;j++){
sum[j]=c[r][j];
}
}
else{
solve(sum,c[++r]);
}
}
for(int j=0;j<=m;j++){
tmp[j]=sum[j];
}
ls=l;//复制
while(a[i].l<ls){
if(ls>r){//如果为空莫队的话,直接赋值
ls--;
for(int j=0;j<=m;j++){
tmp[j]=c[ls][j];
}
}
else{
solve(tmp,c[--ls]);
}
}
for(int j=0;j<=m;j++){
ans[a[i].id]+=(tmp[j]*b[j])%mod;
ans[a[i].id]%=mod;
}
}
for(int i=1;i<=q;i++){
cout<<ans[i]<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9760kb
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: 2ms
memory: 9784kb
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: 2ms
memory: 9880kb
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...