思路:考虑离线操作,以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系列(十一)架构分析之Supervisor-管理Worker进程的事件线程

    处理流程:   方法原型: (defn sync-processes [supervisor]) 函数说明: Supervisor是一个supervisor-data对象. 从local-state中 ...

  2. 新浪微博、腾讯微博、QQ空间、人人网、豆瓣 一键分享API

    新浪微博: http://service.weibo.com/share/share.php?url= count=表示是否显示当前页面被分享数量(1显示)(可选,允许为空) & url=将页 ...

  3. 问题-[Delphi]提示Can't load package:dclite70.bpl解决方法

    问题现象:提示Can't load package:dclite70.bpl 问题原因:全是Window2003的Data Execution Prevention(DEF数据执行保护)造成的. 解决 ...

  4. flot中文说明文档 简版

    Flot参考文档: 一.对绘图函数plot的调用:var plot=$.plot(placeholder,data,options) ----------- placeholder --------- ...

  5. PAT 1003. Emergency (25)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  6. SQLite简介

    1.SQLite简介 SQLite第一个Alpha版本诞生于2000年5月. 至今已经有9个年头了. 而在今年的5月SQLite也迎来了一个新的里程: SQLite 3. SQLite官方网站: ht ...

  7. Activity 的启动模式

    好久没用过那几种activity的启动模式了,如今看到singletop竟然傻了眼,完全忘记了这几种启动模式的区别!隧将两年前的总结翻出来,通读一遍那晦涩难懂的记录,又理解了一遍,在以前记录的基础上, ...

  8. HttpClientUtil

    package com.uniubi.management.util; import java.io.IOException; import java.io.InterruptedIOExceptio ...

  9. get-random生成电话号码

    "138"+((0..9|Get-Random -count 10) -join $null) From:http://blog.csdn.net/shrekz/article/d ...

  10. Caused by: java.lang.NoClassDefFoundError: freemarker/cache/TemplateLoader

    1.错误描写叙述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -he ...