Turtles (非纯分块)
2024-09-04 04:37:09
http://codeforces.com/contest/103/problem/D
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define faster ios::sync_with_stdio(0);cin.tie(0) inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} /********************************************************************/ const int maxn = 3e5+;
ll n, m;
ll a[maxn];
ll cx[maxn], cy[maxn];
int kiss = ;
vector<int> d[];
ll dp[maxn];
ll ans[maxn]; int main(){
n = read();
for(int i = ;i <= n;i++)
a[i] = read();
m = read();
for(int i = ;i <= m;i++){
cx[i] = read(), cy[i] = read();
if(cy[i] < kiss)
d[cy[i]].push_back(i);
else{
ll ans1 = ;
for(int j = cx[i];j <= n;j += cy[i]){
ans1 += a[j];
}
ans[i] = ans1;
}
}
for(int i= ;i < kiss;i++){
if(d[i].size()){
for(int j = n;j;j--){ //From the back forward
if(j+i > n)
dp[j] = a[j];
else
dp[j] = dp[j+i] + a[j];
}
for(int j = ;j < d[i].size();j++)
ans[d[i][j]] = dp[cx[d[i][j]]];
}
}
for(int i = ;i <= m;i++)
cout << ans[i] << endl;
return ;
}
最新文章
- Notes: DOM Range
- iOS 隐藏键盘的几种常见方法
- python3爬虫再探之EXCEL(续)
- php简单计数器程序(文本计数器、图形计数器)
- dedecms 在php7.0无法安装
- linux系统文件夹的作用 good
- 自定义AccessDeniedHandler
- python3中的进程
- oo第二单元的自白
- hadoop/hdfs/yarn 详细命令搬运
- hive 创建orc表
- js的语言的理解
- gitlab自动备份恢复与卸载
- win7下docker环境centos容器中安装mysql5.7
- Linux知识(6)----VIM
- MFC进度条刷新处理
- php小练习——实现几种不同的金字塔
- Spring项目的发展历史和SpringBoot的发展历史
- C# LINQ(3)
- hadoop遇到的问题(汇总)