记录编号 |
141983 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[JSOI 2008] 最大数 |
最终得分 |
100 |
用户昵称 |
Asm.Def |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.279 s |
提交时间 |
2014-12-05 20:41:33 |
内存使用 |
1.84 MiB |
显示代码纯文本
//Asm_Def
#include <iostream>
#include <cctype>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
template<typename T>inline void getd(T &x){
char c = getchar();
bool minus = 0;
while(!isdigit(c) && c != '-')c = getchar();
if(c == '-')minus = 1, c = getchar();
x = c - '0';
while(isdigit(c = getchar()))x = x * 10 + c - '0';
if(minus)x = -x;
}
/*======================================================*/
const int maxn = 200002;
typedef long long LL;
inline int lowbit(int x){return x & -x;}
struct Fenwick{
LL A[maxn];
int iter;
Fenwick():iter(maxn - 1){}
inline void insert(LL x){
A[iter] = x;
int i = iter + lowbit(iter);--iter;
while(i < maxn){
if(x > A[i])A[i] = x;
i += lowbit(i);
}
}
inline LL getmax(int L){
int i = iter + L;
LL ans = 0;
while(i >= iter){
if(ans < A[i])ans = A[i];
i ^= lowbit(i);
}
return ans;
}
}BIT;
int main(){
#if defined DEBUG
//freopen("test", "r", stdin);
#else
freopen("bzoj_1012.in", "r", stdin);
freopen("bzoj_1012.out", "w", stdout);
#endif
LL D, x, t = 0;
int M, opt;
getd(M), getd(D);
while(M--){
while(!isalpha(opt = getchar()));
getd(x);
if(opt == 'Q')
printf("%lld\n", t = BIT.getmax(x));
else BIT.insert((t + x) % D);
}
#if defined DEBUG
//cout << endl << (double)clock()/CLOCKS_PER_SEC << endl;
#endif
return 0;
}