比赛 |
区间问题练习 |
评测结果 |
AAAAAAAAAA |
题目名称 |
最大数 |
最终得分 |
100 |
用户昵称 |
Tabing010102 |
运行时间 |
0.737 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2017-04-21 19:06:04 |
显示代码纯文本
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const LL maxn = 200000+100;
const LL INF = 10000000000000000;
FILE *fin, *fout;
LL MOD, last=0, M;
//卡常大法好
LL qrc() {
char c;
while(c!='A' && c!='Q') c = fgetc(fin);
return c=='Q'?1:2;
}
LL QrLL() {
LL ans = 0;
char c;
while(c<'0' || c>'9') c = fgetc(fin);
while(c>='0' && c<='9') {
ans *= 10;
ans += c-'0';
c = fgetc(fin);
}
return ans;
}
void QwLL(LL x) {
char buf[20];
LL len = 1;
while(1) {
buf[len] = x%10 + '0';
x /= 10;
if(!x) break;
len++;
}
for(LL i = len; i >= 1; i--) fputc(buf[i], fout);
}
inline LL max(LL a, LL b) { return a<b?b:a; }
struct SEG {
LL n;
LL maxv[maxn*4];
SEG() {
this->n = 0;
memset(maxv, 0, sizeof(maxv));
}
void upcurpinfo(LL o, LL L, LL R) {
if(R > L) maxv[o] = max(maxv[o*2], maxv[o*2+1]);
}
LL p, av;
void add(LL o, LL L, LL R) {
if(L == R) {
maxv[o] += av;
} else {
LL lc=o*2, rc=o*2+1;
LL M = L + (R-L)/2;
if(p <= M) add(lc, L, M);
else add(rc, M+1, R);
}
upcurpinfo(o, L, R);
}
LL oL, oR;
LL qmax(LL o, LL L, LL R) {
if(L>=oL && R<=oR) {
return maxv[o];
} else {
LL lc=o*2, rc=o*2+1;
LL M = L + (R-L)/2;
LL tans = -INF;
if(M >= oL) tans = max(tans, qmax(lc, L, M));
if(M < oR) tans = max(tans, qmax(rc, M+1, R));
return tans;
}
}
void execute_command() {
LL op = qrc();
LL tmp = QrLL();
//fin >> tmp;
if(op == 1) {
LL l = n-tmp+1;
oL = l; oR = n;
last = qmax(1, 1, maxn);
// fout << last << endl;
QwLL(last); fputc('\n', fout);
} else {
LL anv = (tmp%MOD + last%MOD) % MOD;
n++;
p = n; av = anv;
add(1, 1, maxn);
}
}
};
int main() {
fin = fopen("bzoj_1012.in", "r");
fout = fopen("bzoj_1012.out", "w");
// fin >> M >> MOD;
M = QrLL(); MOD = QrLL();
SEG *D = new SEG();
for(LL i = 1; i <= M; i++) D->execute_command();
return 0;
}