思路:考虑离线操作,以y为关键字排序,对于y相同的一起操作,然后考虑y的范围,当y<=sqrt(n)时,直接O(n)预处理出f[x]表示f[x]+f[x+y]+f[x+2*y]+..+f[x+k*y]的答案,然后这样的y显然不超过sqrt(n)个,复杂度也就是O(n*sqrt(n))的;如果y>sqrt(n),那么这样直接暴力统计答案,因为答案的项数也显然不会超过sqrt(n),这样整个算法的时间复杂度就是O(n*sqrt(n))。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 300005 int n,Q;
int a[maxn];
long long f[maxn],ans[maxn]; struct query{
int x,y,id;
bool operator <(const query &a)const{return y<a.y;}
}q[maxn]; int read(){
int x=;char ch=getchar();
for (;ch<''||ch>'';ch=getchar());
for (;ch>=''&&ch<='';ch=getchar()) x=x*+ch-'';
return x;
} int main(){
n=read();int size=sqrt(n);
for (int i=;i<=n;i++) a[i]=read();
Q=read();
for (int i=;i<=Q;i++) q[i].x=read(),q[i].y=read(),q[i].id=i;
sort(q+,q+Q+);
for (int i=;i<=Q;i++){
if (q[i].y<=size){
int y=q[i].y;
if (y!=q[i-].y) for (int j=n;j;j--) f[j]=(j+y>n?a[j]:f[j+y]+a[j]);
ans[q[i].id]=f[q[i].x];
}
else{
int x=q[i].x,y=q[i].y,id=q[i].id;
while (x<=n) ans[id]+=a[x],x+=y;
}
}
for (int i=;i<=Q;i++) printf("%I64d\n",ans[i]);
return ;
}

Codeforces Round #80 Div.1 D的更多相关文章

  1. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  2. Codeforces Round #491 (Div. 2)

    Codeforces Round #491 (Div. 2) https://codeforces.com/contest/991 A #include<bits/stdc++.h> us ...

  3. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  4. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  5. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  6. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  7. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  8. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  9. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

随机推荐

  1. Storm系列(十三)架构分析之Worker-维护ZMQ连接

    Worker根据Topology的定义及分配到自身的任务情况,计算出发出的消息被那些Task接收,由于Worker上分配的任务可能被调整,因此Worker需要定时的更新这些连接信息. ZMQ连接信息更 ...

  2. 问题-delphi 调试(F8)错行处理

    在delphi 7中(其他版本也可能碰到该问题),编译后,代码左边显示蓝色小点,表示哪句代 码是被编译了的,可今天我的一些代码不能显示那些蓝点了,这样也就不能在上面设断点了,而且用F8跟踪发现执行的顺 ...

  3. JavaScript- The Good Parts Chapter 6

    Thee(你) I’ll chase(追逐:追捕) hence(因此:今后), thou(你:尔,汝) wolf in sheep’s array.—William Shakespeare, The ...

  4. javascript函数的4种调用方式

    在javascript中一共有4种函数调用模式,分别是:方法调用模式.函数调用模式.构造函数调用模式和apply(call)调用模式,这4种模式的主要差异在于如何初始化关键参数this. 方法调用模式 ...

  5. Kinect for Windows SDK开发入门(一):开发环境配置

    [译]Kinect for Windows SDK开发入门(一):开发环境配置 前几天无意中看到微软发布了Kinect for windows sensor,进去看了一下Kinect应用的例子,发现K ...

  6. 在Java中如何用String类中的indexof方法得到一个词的出现频率

    public class Test{ public static void main(String[] args) { String s="hello jack hello look me ...

  7. [转载](iPhone开发)Bundle Display Name 改为中文。ap

    原文地址:(iPhone开发)Bundle Display Name 改为中文.app显示为中文作者:小新 要先在info的Localizations加入Chinese(zh-Hant) 再進到inf ...

  8. Hyper-V虚机跨NUMA节点性能影响

    查看单个NUMA节点的内存大小: Hyper-V VM VID NUMA节点\PageCount:83769708376970*4k/1024/1024=32GB Hyper-V VM VID NUM ...

  9. 浅谈C语言中的联合体

    联合体union 当多个数据须要共享内存或者多个数据每次仅仅取其一时.能够利用联合体(union).在C Programming Language 一书中对于联合体是这么描写叙述的: 1)联合体是一个 ...

  10. c语言学习

    #include <stdio.h>void sum_diff(int *n1,int *n2,int *sum,int *diff){ *sum=*n1+*n2; *diff=(*n1& ...