797E - Array Queries

思路:

  分段处理;

  当k小于根号n时记忆化搜索;

  否则暴力;

来,上代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 100005 int n,q,ai[maxn],bi[maxn][],size; inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} int dfs(int now,int k)
{
if(now>n) return ;
if(bi[now][k]) return bi[now][k];
else return bi[now][k]=dfs(now+ai[now]+k,k)+;
} int main()
{
in(n),size=sqrt(n);
for(int i=;i<=n;i++) in(ai[i]);
in(q);int p,k;
while(q--)
{
in(p),in(k);
if(k>size)
{
int res=;
while(p<=n)
{
res++;
p+=ai[p]+k;
}
printf("%d\n",res);
}
else printf("%d\n",dfs(p,k));
}
return ;
}

AC日记——Array Queries codeforces 797e的更多相关文章

  1. Array Queries CodeForces - 797E

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

  2. AC日记——Propagating tree Codeforces 383c

    C. Propagating tree time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. AC日记——Cards Sorting codeforces 830B

    Cards Sorting 思路: 线段树: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  4. AC日记——Card Game codeforces 808f

    F - Card Game 思路: 题意: 有n张卡片,每张卡片三个值,pi,ci,li: 要求选出几张卡片使得pi之和大于等于给定值: 同时,任意两两ci之和不得为素数: 求选出的li的最小值,如果 ...

  5. AC日记——Success Rate codeforces 807c

    Success Rate 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  6. AC日记——T-Shirt Hunt codeforces 807b

    T-Shirt Hunt 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> ...

  7. AC日记——Magazine Ad codeforces 803d

    803D - Magazine Ad 思路: 二分答案+贪心: 代码: #include <cstdio> #include <cstring> #include <io ...

  8. AC日记——Broken BST codeforces 797d

    D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...

  9. AC日记——Maximal GCD codeforces 803c

    803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...

随机推荐

  1. TCP close seq问题

    测试mt_hls一条流时,发现会话的时长总是对应不上. 仔细观察发现: 注意 1.包1735 (客户端) 发送FIN 请求,seq = 2435582428 2.包1736,1737,1738 (服务 ...

  2. objc中的类方法和实例方法有什么本质区别和联系

    类方法: 类方法是属于类对象的 类方法只能通过类对象调用 类方法中的self是类对象 类方法可以调用其他的类方法 类方法中不能访问成员变量 类方法中不能直接调用对象方法 类方法是存储在元类对象的方法缓 ...

  3. js实现类bootstrap模态框动画

    在pc端开发,模态框是一个很常用的插件,之前一直用的第三方插件,比如bootstrap,jQuery的模态框插件,最近还用了elementUI的.但是会发现其实动画效果都差不多,那么如何去实现这样一个 ...

  4. 《移动App性能评测与优化》读书笔记

    第一章:内存   内存的主要组成索引: Native Heap:Native代码分配的内存,虚拟机和Android框架本身也会分配 Dalvik Heap:Java代码分配的对象 Dalvik Oth ...

  5. selenium IDE录制

    一.        安装 可以用Firefox打开https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/,在这里边找到和当前firef ...

  6. isinstance()判断数据类型

    判断数据类型isinstance()l=[1,2,3]print(isinstance(l,list))#括号里面第一个填需要判断的数据,第二个是判断条件

  7. python学习总结---函数使用 and 装饰器

    # 函数使用 ### 零碎知识 - 灵活的if-else ```python a = 3 if False else 5 print(a) ''' if False: a = 3 else: a = ...

  8. 安装cloudbase-init和qga批处理

    @echo off title Auto Install color 1F ::CloudBase-Init echo. msiexec /i \\192.168.122.47\cloudbase\C ...

  9. Android 启动项 Activity

    使用SDK创建一个App的时候,基本都会看到这段代码: <activity android:name=".ExampleActivity" android:icon=&quo ...

  10. 爬虫python

    最近看到电影,也看了很多的评论,想了解下大多人对相关电影的评论,正好也在学习Python,就利用其爬虫的强大能力,这里利用Python3.6.1 下面是相关代码: #coding:utf-8 __au ...