题意

n(n≤105)个洞排成一条直线,第ii个洞有力量值ai,当一个球掉进洞ii时就会被立刻弹到i+ai,直到超出n。进行m(m≤105)次操作:

·修改第i个洞的力量值ai。

·在洞xx上放一个球,问该球几次后被哪个洞弹飞出界。

思路

分块暴力,每个块内维护两个信息(块内DP可以求出):

①从当前位置跳出块内需要跳几次num[i]

②从当前块内跳出的下一个位置jump[i]

修改:

只需要将修改元素所在块内信息更新一次即可,单次时间复杂O(√n)

查询:

由起点i不停往下一个块跳jump[i],并且累计次数num[i],在最后一个块内暴力便利一遍就行了

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e5+10;
int n,m,bl,bel[maxn],x,y;
int a[maxn],num[maxn],jump[maxn];
void update(int x)
{
int fr=x*bl,to=fr+bl-1;if(to>n) to=n;
for(int i=to;i>=fr;i--){
if(a[i]+i>to){
num[i]=1;
jump[i]=a[i]+i;
}
else{
num[i]=num[i+a[i]]+1;
jump[i]=jump[i+a[i]];
}
}
}
void query(int x)
{
int ans=0,i,pre;
for(i=x;i<=n;i=jump[i])
ans+=num[i],pre=i;
while(pre+a[pre]<=n)
pre+=a[pre];
printf("%d %d\n",pre,ans);
}
int main()
{
scanf("%d%d",&n,&m);
int op;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
num[i]=0;
jump[i]=i;
}
bl=sqrt(n);
for(int i=0;i<=n/bl;i++)
update(i);
while(m--){
scanf("%d",&op);
if(op==0){
scanf("%d%d",&x,&y);
a[x]=y;
update(x/bl);
}
else{
scanf("%d",&x);
query(x);
}
}
return 0;
}

  

 

(分块)Holes CodeForces - 13E的更多相关文章

  1. Mice and Holes CodeForces - 797F

    Mice and Holes CodeForces - 797F 题意:有n只老鼠和m个洞,都在一个数轴上,老鼠坐标为x[1],...,x[n],洞的坐标为p[1],...,p[m],每个洞能容纳的老 ...

  2. CodeForces 13E. Holes 分块处理

    正解是动态树,太难了,仅仅好分块处理水之.看了看status大概慢了一倍之多..     分块算法大体就是在找一个折衷点,使得查询和改动的时间复杂度都不算太高,均为o(sqrt(n)),所以总的时间复 ...

  3. codeforces 13E . Holes 分块

    题目链接 nextt数组表示这个位置的下一个位置. cnt数组表示这个位置 i 到nextt[i]可以弹几次. end[i] 表示在从 i 弹出去的情况下, 最后一个位置是哪里. 然后就看代码吧. # ...

  4. CodeForces - 13E(分块)

    Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for on ...

  5. CodeForces 13E 分块

    题目链接:http://codeforces.com/problemset/problem/13/E 题意:给定n个弹簧和每个弹簧初始的弹力a[].当球落在第i个位置.则球会被弹到i+a[i]的位置. ...

  6. CodeForces - 13E

    Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for on ...

  7. 构造+分块思想 Codeforces Round #319 (Div. 1) C

    http://codeforces.com/contest/576/problem/C 题目大意: 给你一个曼哈顿距离的图,然后要求你找到一个链,链穿了所有的点 然后要求这链的长度<=25*10 ...

  8. AC日记——Mice and Holes codeforces 797f

    797F - Mice and Holes 思路: XXYXX: 代码: #include <cmath> #include <cstdio> #include <cst ...

  9. Codeforces Beta Round #13 E. Holes 分块暴力

    E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...

随机推荐

  1. HDU 1087 Super Jumping....(动态规划之最大递增子序列和)

    Super Jumping! Jumping! Jumping! Problem Description Nowadays, a kind of chess game called “Super Ju ...

  2. 前端css图片固定宽高问题

    img需要宽高都固定时,图片往往会因此变形,此时可采用的方法有: 上述代码会使得图片居中,边缘部分不显示.这是在图片大小跟container大小差不多的情况下.如果图片很大的话,只显示中心部分是不行的 ...

  3. 手机网页H5 自适应不同分辨率的屏幕 必学标签meta之viewport

    viewport 语法介绍 <meta name="viewport"content=" height = [pixel_value | device-height ...

  4. 【34.54%】【codeforces 675E】Trains and Statistic

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. centos7 teamviewer

    Step 1: Install the prerequisites. # yum install glibc alsa-lib freetype libICE libSM libX11 libXau ...

  6. EF 配置多个数据库

    1.先创建两个DbContext using System; using System.Data.Common; using System.Data.Entity; using System.Data ...

  7. python简单小程序

    #足球队寻找10 到12岁的小女孩(包含10岁和12岁),编写程序询问用户性别和年龄,然后显示一条消息指出这个人是否可以加入球队,询问10次,输出满足条件的总人数#询问10次,输出满足要求的总人数 o ...

  8. 006 管理Ceph的RBD块设备

    一, Ceph RBD的特性 支持完整和增量的快照 自动精简配置 写时复制克隆 动态调整大小 二.RBD基本应用 2.1 创建RBD池 [root@ceph2 ceph]# ceph osd pool ...

  9. 20191024-3 互评Alpha阶段作品——都是为了生活组

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9860 评价:都是为了生活组——All  For  Eating 基于NAB ...

  10. $BZOJ3232$ 圈地游戏 网络流

    正解:最小割+01分数规划 解题报告: 传送门$QwQ$ 感$jio$这个好像是$NOIp2018$集训的时候$cjk$学长讲01分数规划的时候港的,,,?$QwQ$虽然我还是不会嘤 首先看到这个分数 ...