_bzoj1012 [JSOI2008]最大数maxnumber【Fenwick Tree】

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1012

裸的树状数组。

#include <cstdio>
#include <algorithm>

const int maxm = 200005;

int m, d, c[maxm], n, t1, t;
char opr;

inline void upd(int pos, int val) {
	while (pos) {
		c[pos] = std::max(c[pos], val);
		pos -= (pos & (-pos));
	}
}
inline int qry(int pos) {
	int rt = -2147483647;
	while (pos <= n) {
		rt = std::max(rt, c[pos]);
		pos += (pos & (-pos));
	}
	return rt;
}

int main(void) {
	scanf("%d%d", &m, &d);
	while (m--) {
		while ((opr = getchar()) < 'A');
		scanf("%d", &t1);
		if (opr == 'A') {
			upd(++n, (int)((long long)(t1 + t) % d));
		}
		else {
			printf("%d\n", t = qry(n - t1 + 1));
		}
	}
	return 0;
}

  

posted @ 2016-12-09 19:17  ciao_sora  阅读(114)  评论(0编辑  收藏  举报