QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#418597#8717. 骰子tzxydby#TL 1ms4116kbC++142.0kb2024-05-23 14:42:432024-05-23 14:42:44

Judging History

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

  • [2024-05-23 14:42:44]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:4116kb
  • [2024-05-23 14:42:43]
  • 提交

answer

#include<cstdio>
#include<cstring>
#define mo 1000000007
using namespace std;
int n,m,q,in1,in2,b[210],p[1510][210],res[210];
inline int MO(int x)
{
	return x<mo?x:x-mo;
}
inline void wk(int* a,int* b,int* c)
{
	memset(a,0,sizeof(int)*(m+1));
	for(int i=0;i<=m;i++)
	{
		for(int j=0;j+i<=m;j++)
		{
			a[i+j]=MO(a[i+j]+1ll*b[i]*c[j]%mo);
		}
	}
}
struct node
{
	int **dat;
	node *lch,*rch;
	node(int l,int r)
	{
		if(l==r)
		{
			dat=nullptr;
			return;
		}
		dat=new int*[r-l+1];
		for(int i=0;i<=r-l;i++)
		{
			dat[i]=new int[m+1];
		}
		int md=l+r>>1;
		memcpy(dat[md-l],p[md],sizeof(int)*(m+1));
		memcpy(dat[md+1-l],p[md+1],sizeof(int)*(m+1));
		for(int i=md-1;i>=l;i--)
		{
			wk(dat[i-l],dat[i-l+1],p[i]);
		}
		for(int i=md+2;i<=r;i++)
		{
			wk(dat[i-l],dat[i-l-1],p[i]);
		}
		lch=new node(l,md);
		rch=new node(md+1,r);
	}
	inline int wkot(int x,int y,int l,int r)
	{
		int md=l+r>>1;
		if(x==md+1)
		{
			int ans=0;
			for(int i=0;i<=m;i++)
			{
				ans=MO(ans+1ll*b[i]*dat[y-l][i]%mo);
			}
			return ans;
		}
		else if(y==md)
		{
			int ans=0;
			for(int i=0;i<=m;i++)
			{
				ans=MO(ans+1ll*b[i]*dat[x-l][i]%mo);
			}
			return ans;
		}
		else if(x<=md&&y>md)
		{
			int ans=0;
			wk(res,dat[x-l],dat[y-l]);
			for(int i=0;i<=m;i++)
			{
				ans=MO(ans+1ll*b[i]*res[i]%mo);
			}
			return ans;
		}
		else return y<md?lch->wkot(x,y,l,md):rch->wkot(x,y,md+1,r);
	}
};
node *no;
int main()
{
	// freopen("1.in","r",stdin);
	scanf("%d%d%d",&n,&m,&q);
	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]);
			p[i][j]=MO(p[i][j]);
		}
	}
	no=new node(1,n);
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d",&in1,&in2);
		if(n==1)
		{
			int ans=0;
			for(int i=0;i<=m;i++)
			{
				ans=MO(ans+1ll*p[1][i]*b[i]%mo);
			}
			printf("%d\n",ans);
		}
		else printf("%d\n",no->wkot(in1,in2,1,n));
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4116kb

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

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

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...

result: