QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#418362#8717. 骰子Alan26TL 1ms7760kbC++141.4kb2024-05-23 13:12:462024-05-23 13:12:59

Judging History

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

  • [2024-05-23 13:12:59]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7760kb
  • [2024-05-23 13:12:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1505,mod=1e9+7,M=6e5+5;
typedef long long ll;
int n,m,q;
ll b[205],p[N][205],a[N],t[N][205];
struct Edge{
	int l,r,id,res;
}c[M];
bool cmp1(Edge a,Edge b){
	if(a.l<b.l)return true;
	if(a.l==b.l)return a.r<b.r;
	return false;
}
bool cmp2(Edge a,Edge b){
	return a.id<b.id;
}
void cal(int x,int y){
	int l=c[x].l,r=c[x].r,ml=l,mr=r;
	for(int i=0;i<=m;i++)t[l][i]=p[l][i];
	for(int i=l+1;i<=r;i++){
		t[i][0]=p[i][0]*t[i-1][0]%mod;
		for(int j=1;j<=m;j++)
			for(int k=0;k<=j;k++)t[i][j]=(t[i][j]+p[i][k]*t[i-1][j-k])%mod;
	}
	ll res=0;
	for(int i=0;i<=m;i++)res=(res+t[r][i]*b[i])%mod;
	c[x].res=res;
	for(int i=x+1;i<=y;i++){
		res=0;
		l=r,r=c[i].r,mr=r;
		for(int j=l+1;j<=r;j++){
			t[j][0]=p[j][0]*t[j-1][0]%mod;
			for(int k=1;k<=m;k++)
				for(int h=0;h<=k;h++)t[j][k]=(t[j][k]+p[j][h]*t[j-1][k-h])%mod;
		}
		for(int j=0;j<=m;j++)res=(res+t[r][j]*b[j])%mod;
		c[i].res=res;
	}
	for(int i=ml;i<=mr;i++)
		for(int j=0;j<=m;j++)t[i][j]=0;
}
int main(){
	cin>>n>>m>>q;
	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>>p[i][j];
	int l,r;
	for(int i=1;i<=q;i++){
		cin>>l>>r;
		c[i]={l,r,i,0};
	}
	sort(c+1,c+q+1,cmp1);
	int pre,now=1,nl=c[1].l;
	while(now<=q){
		pre=now;
		while(c[now+1].l==nl)now++;
		cal(pre,now);
		now++;
	}
	sort(c+1,c+q+1,cmp2);
	for(int i=1;i<=q;i++)cout<<c[i].res<<'\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 7756kb

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: 7760kb

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: 1ms
memory: 7740kb

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:


result: