QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108624#2887. 区间矩阵乘法ZSH_ZSHTL 2ms3728kbC++14718b2023-05-25 20:05:592023-05-25 20:06:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-25 20:06:02]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3728kb
  • [2023-05-25 20:05:59]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for (register int i=(a);i<=(b);i++)
#define drep(i,a,b) for (register int i=(a);i>=(b);i--)
typedef long long ll;
using namespace std;

typedef unsigned int uint;
const int N=200010,M=sqrt(N)+5;

int n;
uint a[N],s[N][M];

int main()
{
	cin>>n;
	rep(i,1,n) cin>>a[i];
	int mx=sqrt(n);
	rep(i,1,n)
	{
		rep(d,1,mx)
		{
			s[i][d]=a[i];
			if (i>=d) s[i][d]+=s[i-d][d];
		}
	}
	
	int q; cin>>q;
	rep(_,1,q)
	{
		int d,p1,p2; cin>>d>>p1>>p2;
		uint ans=0;
		rep(i,0,d-1)
		{
			uint v=s[p2+(i+1)*d-1][1]-s[p2+i*d-1][1];
			uint w=s[p1+(d-1)*d+i][d];
			if (p1+i>=d) w-=s[p1+i-d][d];
			ans+=v*w;
		}
		printf("%u\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3728kb

input:

8
1 2 2 2 2 2 1 1
2
2 2 2
1 3 7

output:

32
2

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

200000
110569 155 159393 154631 169597 134901 75060 60085 189794 169502 10184 170809 170894 5697 83892 99814 97985 11604 39943 171446 77088 44463 60432 121559 54578 115592 151722 115322 147103 126168 55464 42044 181426 196809 58680 173065 136429 76030 109558 78475 161094 46875 1564 177386 108053 828...

output:

4189305368
55181820
2129409470
700818946
3501766645
1730563858
3899557935
4020833941
1896225959
3402813306
1636148212
106070907
1868972913
406568818
4117597926
65997073
3713307242
3060762232
2968862403
705700646
1131106229
4118099190
420297313
2760229439
4118078127
4042393869
1482472642
1219344853
3...

result: