求调
查看原帖
求调
1298492
zhaoyonghao楼主2025/1/5 13:48
#include <bits/stdc++.h>
using namespace std;

int a[200005], st[200005][25], _log2[200005];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int m, d, cnt = 0, last = 0;
	cin >> m >> d;
	int lg = 0, jsq = 0;
	for (int i = 1; i <= 200005; i++)
	{
		_log2[i] = lg;
		jsq++;
		if (jsq == (1 << lg))
		{
			jsq = 0;
			lg++;
		}
	}
	for (int k = 1; k <= m; k++)
	{
		char opt;
		cin >> opt;
		if (opt == 'A')
		{
			int x;
			cin >> x;
			a[++cnt] = (x + last) % d;
			for (int j = 1; (1 << j) <= cnt; j++)
			{
				int l = cnt - (1 << j) + 1;
				st[l][j] = max(st[l][j - 1], st[l + (1 << j - 1)][j - 1]);
			}
			st[cnt][0] = a[cnt];
		}
		if (opt == 'Q')
		{
			int len;
			cin >> len;
			int l = cnt - len + 1;
			int x = _log2[cnt - l];
			int ans = max(st[l][x], st[cnt - (1 << x) + 1][x]);
			cout << ans << "\n";
			last = ans;
		}
	}
	return 0;
}

2025/1/5 13:48
加载中...