求卡常
查看原帖
求卡常
408071
TankYu楼主2022/4/5 10:34

RT,卡不动了,差0.06s

#include <iostream>
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
using namespace std;

char buf[1 << 23], *p1 = buf, *p2 = buf, obuf[1 << 23], *O = obuf;
const int N = 2E6 + 100;
#define getchar() (p1 == p2 &&(p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)

inline int rd()
{
	int x = 0, f = 1;
	char ch = getchar();
	while (!isdigit(ch))
		{
			if (ch == '-')
				f = -1;
			ch = getchar();
		}
	while (isdigit(ch))
		x = x * 10 + (ch ^ 48), ch = getchar();
	return x * f;
}

inline void write(register int x)
{
	if (x < 0)
		putchar(45), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 ^ 48);
}

int a[N];
int q[N];
int sum[N];
int key;


int main()
{
	int n;
	int m;
	int y, z;
	int opt;
	int i;
	n = rd();
	for (i = 0; i < n; ++i)
		{
			a[i] = rd();
		}
	sum[n - 1] = 1;
	for (i = n - 2; i >= 0; --i)
		{
			sum[i] = sum[i + a[i]] + 1;
		}
	m = rd();
	while (m--)
		{
			opt = rd();
			if (opt == 1)
				{
					z = rd(), q[++key] = z;
				}
			else
				{
					y = rd(), z = rd();
					for (i = 1; i <= key; ++i)
						{
							write(sum[q[i]]), putchar('\n');
						}
					key = 0, a[y] = z;
					for (i = y; i >= 0; --i)
						{
							sum[i] = (i + a[i] >= n ? 1 : sum[i + a[i]] + 1);
						}
				}
		}
	for (i = 1; i <= key; ++i)
		{
			write(sum[q[i]]), putchar('\n');
		}
	return 0;
}
2022/4/5 10:34
加载中...