比赛 |
2025.3.6 |
评测结果 |
AAAAAAAAAA |
题目名称 |
弹飞绵羊 |
最终得分 |
100 |
用户昵称 |
健康铀 |
运行时间 |
1.784 s |
代码语言 |
C++ |
内存使用 |
6.14 MiB |
提交时间 |
2025-03-06 21:02:36 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int c[1000000];
struct node{
int l,r;
}a[1000000];
int a1[1000000],b[1000000],d[1000000],n;
void xz(int l,int r){
for(int i=r;i>=l;i--){
if(i+a1[i]>a[c[i]].r){
b[i]=i+a1[i];
d[i]=1;
}else{
b[i]=b[i+a1[i]];
d[i]=d[i+a1[i]]+1;
}
}
}
int ask(int x){
int ans=0;
while(x<n){
ans+=d[x];
x=b[x];
}
return ans;
}
int main(){
freopen("bzoj_2002.in","r",stdin);
freopen("bzoj_2002.out","w",stdout);
ios::sync_with_stdio(NULL);
cin.tie(NULL);
cin>>n;
for(int i=0;i<n;i++)
cin>>a1[i];
for(int i=0;i<n;i++)
c[i]=i/450;
for(int i=0;i<=c[n-1];i++){
a[i].l=i*450;
a[i].r=(i+1)*450-1;
}
a[c[n-1]].r=n-1;
xz(0,n-1);
int q;
cin>>q;
while(q--){
int opt,x,y;
cin>>opt>>x;
if(opt==1){
cout<<ask(x)<<'\n';
}else{
cin>>y;
a1[x]=y;
xz(a[c[x]].l,a[c[x]].r);
}
}
}