bzoj2002 弹飞绵羊【分块】
来源:互联网 发布:怎么在阿里云里备案 编辑:程序博客网 时间:2024/05/16 11:19
解题思路:
我们可以在分块后维护每个位置弹出该块所需步数和弹到的位置,这样查询和修改都是
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<cmath>#include<ctime>#include<vector>#include<set>#include<map>#include<queue>#define ll long longusing namespace std;int getint(){ int i=0,f=1;char c; for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar()); if(c=='-')f=-1,c=getchar(); for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0'; return i*f;}const int N=200005;int n,m,S,cnt;int k[N],st[N],pt[N],id[N],l[N];int calc(int x){ int res=0; for(;x;x=pt[x])res+=st[x]; return res;}void modify(int x){ k[x]=getint(); for(int i=x;i>=l[id[x]];i--) { if(i+k[i]>n)st[i]=1,pt[i]=0; else if(id[i]!=id[i+k[i]])st[i]=1,pt[i]=i+k[i]; else st[i]=st[i+k[i]]+1,pt[i]=pt[i+k[i]]; }}int main(){ //freopen("lx.in","r",stdin); n=getint();S=sqrt(n); for(int i=1;i<=n;i++)k[i]=getint(); if(n%S)cnt=n/S+1; else cnt=n/S; for(int i=1;i<=cnt;i++)l[i]=(i-1)*S+1; for(int i=1;i<=n;i++)id[i]=(i-1)/S+1; for(int i=n;i;i--) { if(i+k[i]>n)st[i]=1; else if(id[i]!=id[i+k[i]])st[i]=1,pt[i]=i+k[i]; else st[i]=st[i+k[i]]+1,pt[i]=pt[i+k[i]]; } m=getint(); while(m--) { int op=getint(),x=getint()+1; if(op==1)cout<<calc(x)<<'\n'; else modify(x); } return 0;}
阅读全文
0 0
- bzoj2002 弹飞绵羊【分块】
- bzoj2002 弹飞绵羊 分块orLCT
- bzoj2002 [Hnoi2010]Bounce 弹飞绵羊 (分块)
- 【bzoj2002】【Hnoi2010】【Bounce】【弹飞绵羊】【分块】
- 【BZOJ2002】【HNOI2010】弹飞绵羊(分块)
- 分块练习- BZOJ2002-Bounce 弹飞绵羊
- BZOJ2002 Bounce 弹飞绵羊 <分块>
- BZOJ2002(Hnoi2010)[Bounce 弹飞绵羊]--分块
- [bzoj2002][Hnoi2010]Bounce 弹飞绵羊 分块 Link-Cut-Tree
- BZOJ2002 [Hnoi2010]Bounce 弹飞绵羊 解题报告【数据结构】【分块】
- bzoj2002: [Hnoi2010]Bounce 弹飞绵羊(分块)
- 【分块】BZOJ2002(Hnoi2010)[Bounce 弹飞绵羊]题解
- BZOJ2002弹飞绵羊
- 【bzoj2002】弹飞绵羊
- bzoj2002 弹飞绵羊
- 【BZOJ2002】弹飞绵羊
- bzoj2002 弹飞绵羊
- [bzoj2002]弹飞绵羊
- 深度学习|神经网络模型实现手写字分类求解思路
- css选择器
- Andriod基础
- NOIP 2017 Day1 题1:小凯的疑惑 数学问题
- solr的配置
- bzoj2002 弹飞绵羊【分块】
- 开源商业级服务器监控软件Zabbix 3.4.4部署方法
- java--多线程--线程安全的解决方法
- SparkStreamingj集成Kafka的几个重要参数
- 算法爱好者——算法题:堆化 ? 待解决
- 收费软件推广模式探索1
- Spring-boot 报错This application has no explicit mapping for /error, so you are seeing this as a fallb
- Django框架全面讲解 -- 跨站请求伪造(csrf)
- python selenium+phontomjs的详细用法及简单案例