为啥分块被爆卡......
查看原帖
为啥分块被爆卡......
792297
doublebreathing楼主2024/3/23 20:35

蒟蒻的code```cpp

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e6 + 17;
int st[N], ed[N], n, m, to[N], k[N], step[N];
int pos[N], block, t;
int ask(int x) {
	int ans = 0;
	while (x <= n) {
		ans += step[x];
		x = to[x];
	}
	return ans;
}
void modify(int x, int d) {
	k[x] = d;
	for (int i = st[pos[x]]; i <= x; i++) {
		step[i] = 0;
		to[i] = i;
		while (to[i] <= ed[pos[i]]) {
			to[i] += k[to[i]];
			step[i]++;
		}
	}
}
inline int read() {
	int x = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')  f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}

inline void print(int x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9) print(x / 10);
	putchar(x % 10 + '0');
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	n=read();
	for (int i = 1; i <= n; i++) {
		k[i]=read();
		to[i] = i;
	}
	block = sqrt(n);
	t = n / block;
	if (n % block) t++;
	for (int i = 1; i <= t; i++) {
		st[i] = (i - 1) * block + 1;
		ed[i] = i * block;
	}
	ed[t] = n;
	for (int i = 1; i <= n; i++)
		pos[i] = (i - 1) / block + 1;
	for (int i = 1; i <= n; i++) {
		while (to[i] <= ed[pos[i]]) {
			to[i] += k[to[i]];
			step[i]++;
		}
	}
	m=read();
	while (m--) {
		int a, b, c;
		a=read();
		if (a == 1) {
			b=read();
			print(ask(b+1));
			puts("");
		} else {
			b=read(),c=read();
			modify(b + 1, c);
		}
	}
	return 0;
}
2024/3/23 20:35
加载中...