Time to Raid Cowavans  

题意:

询问 下标满足 a + b * k 的和是多少。

题解:

将询问分块。

将b >= blo直接算出答案。

否则存下来。

存下来之后,对于每个b扫一遍数组,然后同时处理相同b的询问。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define Show(x) cout << x << ' ';
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 3e5 + ;
int n, m, k, p;
int w[N];
LL tot[N];
LL ans[N];
struct Node{
int a, b, id;
}q[N];
bool cmp(Node x1, Node x2){
return x1.b < x2.b;
}
int main(){
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%d", &w[i]);
scanf("%d", &p);
k = sqrt(n);
int t = , a, b;
LL tmp;
for(int i = ; i <= p; i++){
scanf("%d%d", &a, &b);
if(b >= k){
tmp = ;
for(int i = a; i <= n; i += b)
tmp += w[i];
ans[i] = tmp;
}
else {
q[t].a = a;
q[t].b = b;
q[t].id = i;
t++;
}
}
sort(q,q+t,cmp);
for(int i = ; i < t; i++){
if(i == || q[i].b != q[i-].b){
b = q[i].b;
for(int i = n; i >= ; i--){
if(i+b > n) tot[i] = w[i];
else tot[i] = tot[i+b] + w[i];
}
}
ans[q[i].id] = tot[q[i].a];
}
for(int i = ; i <= p; i++){
printf("%I64d\n", ans[i]);
}
return ;
}

最新文章

  1. c 数组与指针的使用注意事项
  2. 新手之自动转存DLL——20150626星期五
  3. addScalar 显式指定返回数据的类型
  4. C++移位运算符
  5. Spring的scope=&quot;prototype&quot;属性
  6. [转] mhvtl虚拟磁带库的安装与应用
  7. 关于VS2010中的TraceDebugging文件夹浅说
  8. 制作Linux下程序安装包——使用脚本打包bin、run等安装包
  9. Qt事件机制浅析(定义,产生,异步事件循环,转发,与信号的区别。感觉QT事件与Delphi的事件一致,而信号则与Windows消息一致)
  10. CAN总线基础
  11. lua读书笔记
  12. .NET Core工程编译事件$(TargetDir)变量为空引发的思考
  13. java 项目打jar包,用cmd运行,并且编写运行脚本
  14. 导航菜单点击图片切换--jquery
  15. Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
  16. 运用HTML5+CSS3和CSS滤镜做的精美的登录界面
  17. string::replace
  18. hdu 5826 physics 物理题
  19. 解析eml文件
  20. PAT 甲级 1150 Travelling Salesman Problem

热门文章

  1. 【JDK】JDK源码分析-LinkedList
  2. netty使用EmbeddedChannel对channel的出入站进行单元测试
  3. HC-08 BLE资料
  4. javascript基础入门知识点整理
  5. 深入理解JVM-类加载器深入解析(3)
  6. 记一次python时间格式转换遇到的坑
  7. Linux基础文件查找
  8. .NETCoreCSharp 中级篇2-3 Linq简介
  9. 内存泄漏排查之:Show me your Memory
  10. jvisualvm/Jconsole监控WAS中间件