社区讨论
RRRRREEEEEE求助
P1198[JSOI2008] 最大数参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lp43xcdx
- 此快照首次捕获于
- 2023/11/18 21:51 2 年前
- 此快照最后确认于
- 2023/11/18 23:56 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
struct node{
int ma,l,r;
}tr[802005];
void pd(int );
void build(int c,int l,int r){
tr[c].l=l;
tr[c].r=r;
if(l==r){
//cin>>tr[c].ma;
return;
}
int mid=(l+r)>>1;
build(c*2,l,mid);
build(c*2+1,mid+1,r);
tr[c].ma=max(tr[c*2].ma,tr[c*2+1].ma);
}
void update(int c,int x,int k){
if(tr[c].l==tr[c].r){
tr[c].ma=k;
return;
}
int mid=(tr[c].l+tr[c].r)/2;
if(x<=mid)update(c*2,x,k);
else update(c*2+1,x,k);
tr[c].ma=max(tr[c*2].ma,tr[c*2+1].ma);
}
int query(int c,int l,int r){
if(tr[c].l==l&&tr[c].r==r){
return tr[c].ma;
}
int mid=(tr[c].l+tr[c].r)>>1;
if(r<=mid){
return query(c*2,l,r);
}else if(l>mid){
return query(c*2+1,l,r);
}else{
return max(query(c*2,l,mid),query(c*2+1,mid+1,r));
}
tr[c].ma=max(tr[c*2].ma,tr[c*2+1].ma);
}
int n,m,x,la=0;
int u=0;
signed main(){
cin>>n>>m;
build(1,1,m);
while(n--){
char op;
cin>>op;
cin>>x;
if(op=='A'){
update(1,u+1,(x+la)%m);
u++;
}else {
if(x==0)la=0;
else
la=query(1,u-x+1,u);
cout<<la<<endl;
}
}
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...