https://scut.online/p/37

一开始想到要根号分块预处理,但是不太懂具体怎么写。想不到如此暴力。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 300000; //预留长出来的600
ll a[MAXN + 800 + 5];
ll res[MAXN + 800 + 5];
ll ans[MAXN + 800 + 5]; struct Query {
int x, y, id;
} q;
vector<Query>v[800 + 5]; int main() {
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
int block = (int)sqrt(n) + 200;
for(int i = 1, x, y; i <= m; ++i) {
scanf("%d%d", &x, &y);
if(y > block) {
//长度比较长,直接暴力统计
for(int j = x; j <= n; j += y)
ans[i] += a[j];
} else {
q.x = x, q.y = y, q.id = i;
v[y].push_back(q);
}
}
for(int y = block; y >= 1; --y) {
for(int i = n; i >= 0; --i) {
//暴力统计后缀和
res[i] = a[i] + res[i + y];
}
int len = v[y].size();
for(int i = 0; i < len; ++i)
ans[v[y][i].id] = res[v[y][i].x];
}
for(int i = 1; i <= m; ++i)
printf("%lld\n", ans[i]);
}

最新文章

  1. java中数组的基本知识
  2. SEO之title优化
  3. 使用Spring Task轻松完成定时任务
  4. ubantu16.04+mxnet +opencv+cuda8.0 环境搭建
  5. 搭建AngualarJS开发环境
  6. IndexOf、IndexOfAny 、Remove
  7. MVC4 学习备忘
  8. Vijos1451圆环取数[环形DP|区间DP]
  9. 闭包 Clousure
  10. linux安装python使用的MySQLdb
  11. CF 578A A Problem about Polyline
  12. 过程化开发2048智力游戏WebApp
  13. linux命名管道通信过程
  14. Android实战简易教程-第九枪(BitmapFactory.Options对资源图片进行缩放)
  15. Ubuntu安装pycharm
  16. matlab取模与取余
  17. Docker 学习7 Dockerfile详解
  18. vlan分类简易解释
  19. .NET并行计算和并发8-QueueUserWorkItem异步
  20. drupal7 判断用户是否具有某个权限

热门文章

  1. dnsmasq+Stunnel+sniproxy加密代理
  2. iOS 指定位置切圆角不生效问题
  3. Element ui 中的Upload用法
  4. SpringCloud 教程 (一) 消息总线(Spring Cloud Bus)
  5. js刷新当前页面的5种方式
  6. Mybatis,模糊查询语句,以及传参数的正确写法
  7. jQuery实现三级联动菜单(鼠标悬停联动)
  8. 最新版本的MySQL的下载和安装(Release: 8.0.12)
  9. python实现RESTful服务(基于flask)
  10. Maven中Jar包冲突,不让某个Jar包打入到工程中