st表全re,有没有大佬能帮我看看?谢谢
查看原帖
st表全re,有没有大佬能帮我看看?谢谢
544520
liugh_楼主2023/4/9 13:13
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
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 << 3) + (x << 1) + (c - '0');
		c = getchar();
	}
	return x * f;
}
inline void write(int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
int maxn[200005][20], lenm, lg2[200005];
inline void refresh() {
	for (int j = 1; j <= lg2[lenm]; ++j)
		for (int k = 1; k + (1 << j) - 1 <= lenm; ++k)
			maxn[k][j] = max(maxn[k][j - 1], maxn[k + (1 << (j - 1))][j - 1]);
}
signed main() {
	memset(lg2, -1, sizeof lg2);
	int m = read(), d = read(), a = 0;
	for (int i = 1; i <= m; ++i) {
		char c = getchar();
		ll n = read();
		if (c == 'A') {
			maxn[++lenm][0] = (n + a) % d;
			lg2[lenm] = lg2[lenm >> 1] + 1;
			refresh();
		} else {
			int l = lenm - n + 1;
			int r = lenm, s = lg2[r - l + 1];
			a = max(maxn[l][s], maxn[r - (1 << s) + 1][s]);
			write(a);
			putchar('\n');
		}
	}
	return 0;
}

2023/4/9 13:13
加载中...