$dp$预处理,暴力。

如果$k > sqrt(n)$,那么答案不会超过$sqrt(n)$,暴力模拟即可。如果$k <= sqrt(n)$,那么可以$dp$预处理打表。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std; int dp[100010][320];
int n,q;
int a[100010]; int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]); int x = (int) sqrt(n);
for(int p=1;p<=x;p++)
{
for(int i=n;i>=1;i--)
{
if(i+a[i]+p>n) dp[i][p] = 1;
else dp[i][p] = dp[i+a[i]+p][p] + 1;
}
} scanf("%d",&q);
for(int i=1;i<=q;i++)
{
int A,B;
scanf("%d%d",&A,&B);
if(B<=x)
{
printf("%d\n",dp[A][B]);
}
else
{
int ans=0;
while(A<=n)
{
ans++;
A=A+a[A]+B;
}
printf("%d\n",ans);
}
}
return 0;
}

CodeForcs 797E Array Queries的更多相关文章

  1. Codeforces 797E - Array Queries

    E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds m ...

  2. AC日记——Array Queries codeforces 797e

    797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...

  3. lightoj Again Array Queries

    1100 - Again Array Queries   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...

  4. codeforces 797 E. Array Queries【dp,暴力】

    题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...

  5. Light OJ-1082 - Array Queries,线段树区间查询最大值,哈哈,水过~~

                                                                                                        ...

  6. Light oj-1100 - Again Array Queries,又是这个题,上次那个题用的线段树,这题差点就陷坑里了,简单的抽屉原理加暴力就可以了,真是坑~~

                                                                              1100 - Again Array Queries ...

  7. Array Queries CodeForces - 797E

    题目链接 非常好的一道题目, 分析,如果用暴力的话,时间复杂度是O(q*n)稳稳的超时 如果用二维DP的话,需要O (n*n)的空间复杂度,会爆空间. 那么分析一下,如果k>sqrt(n)的话, ...

  8. 【codeforces 797E】Array Queries

    [题目链接]:http://codeforces.com/problemset/problem/797/E [题意] 给你一个n个元素的数组; 每个元素都在1..n之间; 然后给你q个询问; 每个询问 ...

  9. [Codeforces 863D]Yet Another Array Queries Problem

    Description You are given an array a of size n, and q queries to it. There are queries of two types: ...

随机推荐

  1. js闭包及问题的解决

    闭包定义,作用 闭包就是能够读取其他函数内部变量的函数. 作用:一个是可以读取函数内部的变量,另一个就是让这些变量的值始终保持在内存中 缺点:闭包会保存函数中的变量在内存中,导致内存消耗大   闭包会 ...

  2. zoj 3229 Shoot the Bullet(有源汇上下界最大流)

    Shoot the Bullethttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442 Time Limit: 2 Second ...

  3. Python print "hello world" SyntaxError: invalid syntax

    刚安装Python,在IDLE中输入print “Hello World”,谁知却发生错误: >>> print "Hello World"SyntaxError ...

  4. MongoDB-3.4集群搭建:分片

    概念 集群拥有三个节点: 分片(sharding),分发路由(query routers)和配置服务器 (config server) Shard 分片是存储了一个集合部分数据的MongoDB实例,每 ...

  5. jQuery插件ASP.NET应用之AjaxUpload

    本次使用AJAXUPLOAD做为上传客户端无刷上传插件,其最新版本为3.9,官方地址:http://valums.com/ajax-upload/ 在页面中引入 jquery.min.1.4.2.js ...

  6. DHTML Object Model&DHTML&DOM

    DHTML Object Model:DHTML对象模型,利用DHTML Object Model可以单独操作页面上的对象,每个HTML标记通过它的ID和NAME属性被操纵,每个对象都具有自己的属性. ...

  7. # 2018高考&自主招生 - 游记

    准备了一整个学期的高考和自主招生终于结束了....从育英出来, 以一个失败者的身份来写游记, 权当为明年的决战提供经验与总结. Day -1, June 5th 下午同学收拾考场, 自己在那里看书.. ...

  8. 基于canvas的图片编辑合成器

    在我们日常的前端开发中,经常会要给服务器上传图片,但是局限很大,图片只能是已有的,假设我想把多张图片合成一张上传就需要借助图片编辑器了,但是现在我们有了canvas合成就简单多了 首先我们看图片编辑器 ...

  9. 环境变量配错了 command not found

    一般就是忘记在PATH 前面加$ 1.可以用whereis或者which命令查看一下有没有这个命令 具体执行which lswhereis ls 2.系统环境变量导致的问题解决方案: exportPA ...

  10. js日期工具

    /** * 日期工具类 */ define(function(require, exports, module) { var constants = require("constants&q ...