社区讨论
分块TLE
P3203[HNOI2010] 弹飞绵羊参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lue5pwnp
- 此快照首次捕获于
- 2024/03/30 21:57 2 年前
- 此快照最后确认于
- 2024/03/31 08:25 2 年前
CPP
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10,INF=0x3f3f3f3f;
#define ll long long
const int K = 9;
int st[N];
int en[N];
int f[N];
//f[i]:表示在i这个位置最少要跳多少次能跳出这个块
int top[N];
//top[i]:表示跳出 i 这个块最后到达那个位置
int a[N];
int main()
{
ios::sync_with_stdio(false) , cin.tie(0);
int n;
cin >> n;
for(int i=0; i<n; i++) cin >> a[i];
for(int i=0; i<n; i++) en[i>>K] = i;
for(int i=n-1; i>=0; i--) st[i>>K] = i;
for(int i=n-1; i>=0; i--)
{
if(i + a[i] > en[i>>K])
{
f[i] = 1 , top[i] = i + a[i];
}else{
f[i] = 1 + f[i+a[i]] , top[i] = top[i+a[i]];
}
}
int q;
cin >> q;
while(q--)
{
int op, x;
cin >> op >> x;
if(op==1)
{
int ans = 0;
while(x < n)
{
ans += f[x] , x = top[x];
}
cout << ans << '\n';
}else{
int y;
cin >> y;
a[x] = y;
for(int i=en[x>>K]; i>=st[i>>K]; i--)
if(i + a[i] > en[i>>K])
{
f[i] = 1 , top[i] = i + a[i];
}else{
f[i] = 1 + f[i+a[i]] , top[i] = top[i+a[i]];
}
}
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...