比赛 区间问题练习 评测结果 AAAAAAAAAA
题目名称 最大数 最终得分 100
用户昵称 kZime 运行时间 0.407 s
代码语言 C++ 内存使用 6.42 MiB
提交时间 2017-04-21 19:47:05
显示代码纯文本
#include <bits/stdc++.h>
#define MAXN 200023
#define ll long long
using namespace std;
int cnt, m;
ll d, tmp;
inline ll get_num() {
	ll k = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}
struct segtree {
	ll mx[MAXN << 2];
	segtree() {
		memset(mx, 0, sizeof(mx));
	}
	void change(int x, int l, int r, int k, ll tmp) {//第k个位置的数值为tmp
		int mid = (l + r) >> 1;
		if(l == r) {
			mx[x] = tmp;
			return;
		}
		else if(k > mid) change(x << 1 | 1, mid + 1, r, k, tmp);
		else if(k <= mid) change(x << 1, l, mid, k, tmp);
		mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
	}
	ll find(int x, int l, int r, int s, int t) {
		int mid = (l + r) >> 1;
		if(l == s && t == r) return mx[x];
		else if(t <= mid) return find(x << 1, l, mid, s, t);
		else if(s > mid) return find(x << 1 | 1, mid + 1, r, s, t);
		else {
			return max(find(x << 1, l, mid, s, mid), find(x << 1 | 1, mid + 1, r, mid + 1, t));
		}
	}
}T;
int main() {
	freopen("bzoj_1012.in", "r", stdin);
	freopen("bzoj_1012.out", "w", stdout);
	m = get_num();
	d = get_num();
	while(m--) {
		char type = getchar();
		for(; !isalpha(type); type = getchar());
		if(type == 'Q') {
			int l = get_num();
			tmp = T.find(1, 1, MAXN, cnt - l + 1, cnt);
			printf("%lld\n", tmp);
		}else {
			ll n = get_num();
			n += tmp;
			n %= d;
			T.change(1, 1, MAXN, ++cnt, n);
		}
	}
}