codeforces contest 13 problem E(分块)
来源:互联网 发布:apm性能监控 java 编辑:程序博客网 时间:2024/06/09 17:00
Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules:
There are N holes located in a single row and numbered from left to right with numbers from 1 toN. Each hole has it's own power (hole numberi has the power ai). If you throw a ball into holei it will immediately jump to hole i + ai, then it will jump out of it and so on. If there is no hole with such number, the ball will just jump out of the row. On each of theM moves the player can perform one of two actions:
- Set the power of the hole a to value b.
- Throw a ball into the hole a and count the number of jumps of a ball before it jump out of the row and also write down the number of the hole from which it jumped out just before leaving the row.
Petya is not good at math, so, as you have already guessed, you are to perform all computations.
The first line contains two integers N andM (1 ≤ N ≤ 105,1 ≤ M ≤ 105) — the number of holes in a row and the number of moves. The second line containsN positive integers not exceeding N — initial values of holes power. The following M lines describe moves made by Petya. Each of these line can be one of the two types:
- 0 a b
- 1 a
For each move of the type 1 output two space-separated numbers on a separate line — the number of the last hole the ball visited before leaving the row and the number of jumps it made.
8 51 1 1 1 1 2 8 21 10 1 31 10 3 41 2
8 78 57 3
这题的操作是真的骚
如果当前点跳的下个点在块内 直接延伸到下一个点的后续结点相当于 把整个块都联系起来了 如果不在一个块内 就将后续结点设置为 后续结点的编号
#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<vector>#include<map>#include <bits/stdc++.h>using namespace std;const int N = 300000+10;typedef long long LL;const LL mod = 998244353;int a[N],next1[N],cnt[N];int lx[N],rx[N],id[N],end1[N];int n, m;void add(int i,int pos){ if(pos>n)next1[i]=n+1, cnt[i]=1, end1[i]=i; else { if(id[i]==id[pos]) { next1[i]=next1[pos]; cnt[i]=cnt[pos]+1; end1[i]=end1[pos]; } else { next1[i]=pos; cnt[i]=1; end1[i]=i; } } return ;}int ans;int solve(int x){ int c=cnt[x]; ans=end1[x]; while(x<=n) { x=next1[x]; if(x>n)break; c+=cnt[x]; ans=end1[x]; } return c;}int main(){ scanf("%d %d", &n, &m); for(int i=1;i<=n;i++) scanf("%d", &a[i]); int k=(int)sqrt(1.0*n),i; for(i=1;i*k<n;i++) { lx[i]=(i-1)*k+1,rx[i]=i*k; for(int j=lx[i];j<=rx[i];j++) id[j]=i; } lx[i]=(i-1)*k+1,rx[i]=n; for(int j=lx[i];j<=rx[i];j++) id[j]=i; for(int i=n;i>=1;i--) add(i,i+a[i]); while(m--) { int x, u, v; scanf("%d", &x); if(x) { scanf("%d", &u); printf("%d %d\n",ans,solve(u)); } else { scanf("%d %d", &u, &v); add(u,u+v); for(int i=u-1;i>=lx[id[u]];i--) add(i,i+a[i]); a[u]=v; } } return 0;}
- codeforces contest 13 problem E(分块)
- codeforces contest 785 problem E(分块)
- codeforces contest 551 problem E(分块)
- codeforces/contest/796/problem/E
- codeforces/contest/797/problem/E
- CodeForces 13E Holes(分块)
- CodeForces 13E. Holes 分块处理
- CodeForces 13E Holes(分块处理)
- [Codeforces 13E] Holes (分块)
- codeforces 13 E. Holes (分块)
- Codeforces Problem - 13E Holes
- codeforces contest/796/problem/D
- codeforces/contest/797/problem/A
- codeforces/contest/797/problem/B
- codeforces/contest/798/problem/B
- Codeforces contest 802 problem G
- Codeforces 551E GukiZ and GukiZiana (分块)
- codeforces 551E GukiZ and GukiZiana 分块
- Codeforces Round #380~#400 div2 总结
- java在调试模式下打断点的时候,断点显示为禁用状态的解决
- 提高PHP代码执行效率小结
- hdu 1233 堆优化prim
- 对海康28181摄像头PS流解码的支持(一)
- codeforces contest 13 problem E(分块)
- 基于R语言的Kaggle案例分析学习笔记(五)
- 【入门】Java登录注册
- mongodb_权限
- js中数组Array的一些常用方法总结
- ROW_NUMBER() OVER(PARTTON BY T.ITEM_CODE ORDER BY T.VERSION DESC)
- PAT乙级1044. 火星数字(20)
- SQL Server 2008无法登录问题
- OkHttp3 简单介绍(一)