luogu3203弹飞绵羊
来源:互联网 发布:松下大连软件怎么样 编辑:程序博客网 时间:2024/04/28 00:17
链接
https://www.luogu.org/problem/show?pid=3203
题解
我知道这个用LCT做看上去很裸,然而我不会哎
分块,每个点记录弹出第一次弹出这个块会到达哪个块,以及多少步弹出这个块。
查询的时候跳跃的单位是块,所以复杂度降为
时间复杂度
代码
//分块#include <cstdio>#include <algorithm>#define maxn 200010#define size 450using namespace std;int N, M, k[maxn], to[maxn], lp[maxn], step[maxn];void update(int x){ if(lp[x+k[x]]!=lp[x] or x+k[x]>=N)to[x]=x+k[x],step[x]=1; else to[x]=to[x+k[x]],step[x]=step[x+k[x]]+1;}void init(){ int i; scanf("%d",&N); for(i=0;i<N;i++)scanf("%d",k+i),lp[i]=i/size; for(i=N-1;i>=0;i--)update(i);}int calc(int x){ int ans=0; for(;x<N;x=to[x])ans+=step[x]; return ans;}void solve(){ int type, a, b, i; scanf("%d",&M); while(M--) { scanf("%d%d",&type,&a); if(type==1)printf("%d\n",calc(a)); else { scanf("%d",&b); k[a]=b; for(i=a;lp[i]==lp[a] and i>=0;i--)update(i); } }}int main(){ init(); solve(); return 0;}
0 0
- luogu3203弹飞绵羊
- 【hnoi2010】弹飞绵羊
- BZOJ2002弹飞绵羊
- 【bzoj2002】弹飞绵羊
- bzoj2002 弹飞绵羊
- 【BZOJ2002】弹飞绵羊
- bzoj2002 弹飞绵羊
- [bzoj2002]弹飞绵羊
- BZOJ2002弹飞绵羊
- 【bzoj2022】弹飞绵羊
- 弹飞绵羊
- bzoj2002弹飞绵羊
- 【BZOJ2002】弹飞绵羊
- 【bzoj2002】弹飞绵羊
- BZOJ2002弹飞绵羊
- BZOJ2002弹飞绵羊
- bzoj2002Bounce 弹飞绵羊
- 弹飞绵羊 分块
- zabbix3.2 添加nginx监控(连接数)
- Android简易实战教程--第五十三话《多彩波浪》
- Objective-C 类方法
- query list与iterate方法
- DataGrip 使用技巧三
- luogu3203弹飞绵羊
- json基础
- 空闲时间学一个Linux命令(19)—— find 命令概览
- poj2253 求生成树的最大边的最小值
- poj2104解题报告
- UIKit Dynamics入门
- python所有错误
- sessionStorage 和 localStorage 使用体会
- ajax上传文件