记录编号 317111 评测结果 AAAAAAAAAA
题目名称 梦游仙境 最终得分 100
用户昵称 Gravatar‎MistyEye 是否通过 通过
代码语言 C++ 运行时间 8.404 s
提交时间 2016-10-07 17:47:12 内存使用 220.68 MiB
显示代码纯文本
#include <cmath>
#include <cstdio>
#include <algorithm>
typedef long long ll;
const ll maxn = 100005;
ll N, Q, B, w[maxn], sum[320][maxn];
int main(){
	freopen("XTTMYXJ.in","r",stdin); freopen("XTTMYXJ.out","w",stdout);
	scanf("%lld%lld", &N, &Q); B = (ll)sqrt((long double)N);
	for(ll i=1; i<=N; ++i) scanf("%lld", w+i);
	for(int i=1; i<=N; ++i)
		for(int j=1; j<=i && j<=B; ++j) {
			sum[j][i] = sum[j][i-j]+w[i];
		}
	ll l, r, jump, cnt;
	for(ll i=1; i<=Q; ++i){
		scanf("%lld%lld%lld", &l, &r, &jump);
		if(jump>B){
			cnt = 0;
			for(ll j=l; j<=r; j+=jump) cnt += w[j];
		}else{
			r = l+(r-l)/jump*jump; 
			cnt = sum[jump][r]-sum[jump][l]+w[l];
		}
		printf("%lld\n", cnt);
	}
	return 0;
}