【CF103D】Time to Raid Cowavans(分块)
题意:

思路:院赛防AK题,然而还没来得及做就被数据出锅的题坑了……

#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<bitset>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 310000
#define M 51
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1)
#define oo 1e9 ll a[N],s[N],ans[N];
int n; struct node
{
int x,y,id;
}b[N]; bool cmp(node a,node b)
{
return a.y<b.y;
} int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lld",&a[i]);
int q;
scanf("%d",&q);
for(int i=;i<=q;i++)
{
scanf("%d%d",&b[i].x,&b[i].y);
b[i].id=i;
}
sort(b+,b+q+,cmp);
for(int i=;i<=q;i++)
if(b[i].y<=(int)sqrt(n))
{
if(i>&&b[i].y==b[i-].y) ans[b[i].id]=s[b[i].x];
else
{
for(int j=;j<=n;j++) s[j]=;
for(int j=n;j>=;j--)
{
s[j]=a[j];
if(j+b[i].y<=n) s[j]+=s[j+b[i].y];
}
ans[b[i].id]=s[b[i].x];
}
}
else
{
ll t=;
int j=b[i].x;
while(j<=n)
{
t+=a[j];
j+=b[i].y;
}
ans[b[i].id]=t;
}
for(int i=;i<=q;i++) printf("%lld\n",ans[i]);
return ;
}
【CF103D】Time to Raid Cowavans(分块)的更多相关文章
- Codeforces Beta Round #80 (Div. 1 Only) D. Time to Raid Cowavans 分块
D. Turtles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/103/problem/D ...
- 题解【CF103D Time to Raid Cowavans】
Description 给一个序列 \(a\) ,\(m\) 次询问,每次询问给出 \(t, k\) .求 \(a_t + a_{t+k}+a_{t+2k}+\cdots+a_{t+pk}\) 其中 ...
- CF103D Time to Raid Cowavans 根号分治+离线
题意: 给定序列 $a,m$ 次询问,每次询问给出 $t,k$. 求 $a_{t}+a_{t+k}+a_{t+2k}+.....a_{t+pk}$ 其中 $t+(p+1)k>n$ 题解: 这种跳 ...
- CodeForces 103D Time to Raid Cowavans 分块+dp
先对b从小到大sort,判断b是不是比sqrt(n)大,是的话就直接暴力,不是的话就用dp维护一下 dp[i]表示以nb为等差,i为起点的答案,可以节省nb相同的情况 #include<bits ...
- D. Time to Raid Cowavans 分块暴力,感觉关键在dp
http://codeforces.com/contest/103/problem/D 对于b大于 sqrt(n)的,暴力处理的话,那么算出每个的复杂度是sqrt(n),就是把n分成了sqrt(n)段 ...
- Codeforces Beta Round #80 (Div. 1 Only) D. Time to Raid Cowavans 离线+分块
题目链接: http://codeforces.com/contest/103/problem/D D. Time to Raid Cowavans time limit per test:4 sec ...
- CodeForces 103D Time to Raid Cowavans 询问分块
Time to Raid Cowavans 题意: 询问 下标满足 a + b * k 的和是多少. 题解: 将询问分块. 将b >= blo直接算出答案. 否则存下来. 存下来之后,对于每个b ...
- Codeforces103D - Time to Raid Cowavans
Portal Description 给出长度为\(n(n\leq3\times10^5)\)的序列\(\{a_n\}\),进行\(q(q\leq3\times10^5)\)次询问:给出\(x,y\) ...
- CodeForces 103 D Time to Raid Cowavans
Time to Raid Cowavans 题意:一共有n头牛, 每头牛有一个重量,m次询问, 每次询问有a,b 求出 a,a+b,a+2b的牛的重量和. 题解:对于m次询问,b>sqrt(n) ...
随机推荐
- Android: Requesting root access in your app
package com.certusnet.videomonitor; import java.util.List; import java.io.IOException; import java.i ...
- linux手动安装flash插件
下载好之后,将解压的文件 1,将libflashplayer.so拷到firefox的插件目录/usr/lib/firefox/browser/plugin/ sudo cp libflashplay ...
- 用命令部署WebPart
Webpart一般是一个wsp文件,可以在VS里面通过右键来部署.但一般真正的生产服务器上面是不会安装VS的,所以一般情况下是把wsp文件拷贝到服务器上面然后启动PowerShell用命令来部署. 部 ...
- Linux初步——常用简单命令
散乱的记录,目前是边学边用,以后有机会再整理 curl命令 发起一个HTTP请求,如:curl "http://www.baidu.com" 加上-I选项查看HTTP协议头的信息, ...
- 【APUE】Chapter15 Interprocess Communication
15.1 Introduction 这部分太多概念我不了解.只看懂了最后一段,进程间通信(IPC)内容被组织成了三个部分: (1)classical IPC : pipes, FIFOs, messa ...
- Python中该使用%还是format来格式化字符串?
%还是format 1.皇城PK Python中格式化字符串目前有两种阵营:%和format,我们应该选择哪种呢? 自从Python2.6引入了format这个格式化字符串的方法之后,我认为%还是fo ...
- 数据库学习(二) case when then else end 的使用
case函数还用来统计数据的,参考资料:https://www.cnblogs.com/qlqwjy/p/7476533.html 这里我只是整理下工作中使用的到案例: 查询语句: SELECT t. ...
- JavaScript调试中Console命令
JS调试中,用console.log 感觉比 alert 好用,不用弹出窗口,还要关闭.除了console.log()其他命令没怎么用过,先在这里记一下,用到时在看看 一.显示信息的命令 consol ...
- (转)简述47种Shader Map的渲染原理与制作方法
在Shader中会使用各种不同图参与渲染,所以简单地总结下各种图的渲染原理.制作方法,最后面几种是程序生成图. 1. Albedo 2. Diffuse(Photographic) 从上图可以看出来, ...
- ThinkPHP自定义成功界面、失败界面、异常界面
在ThinkPHP的手册中,附录里边的配置参考,有一个模板引擎设置. 或者在手册里面的控制器,跳转和重定向里面. 紧接着,就讲到了如何自定义这些界面. 将上诉的配置参数写到到配置文件里,修改路径到自己 ...