求大佬帮我调代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int M,D,t,N;
char c[1];
int tree[800010];
void update(int l,int r,int rt,int a,int b){
if(l==r){
tree[rt]=b;
return;
}
int mid=(l+r)>>1;
tree[rt<<1]=tree[rt<<1|1]=tree[rt];
if(a<=mid) update(l,mid,rt<<1,a,b);
else update(mid+1,r,rt<<1|1,a,b);
tree[rt]=max(tree[rt<<1],tree[rt<<1|1]);
return;
}
int query(int l,int r,int rt,int a,int b){
if(a<=l&&b>=r) return tree[rt];
int mid=(l+r)>>1;
int maxs=0;
if(a<=mid) maxs=max(maxs,query(l,mid,rt<<1,a,b));
if(b>mid) maxs=max(maxs,query(mid+1,r,rt<<1|1,a,b));
return maxs;
}
signed main(){
scanf("%lld%lld",&M,&D);
while(M--){
scanf("%s",c);
if(c[0]=='Q'){
int L;
scanf("%lld",&L);
t=query(1,N,1,N-L+1,N);
printf("%lld\n",t);
}else{
int n;
scanf("%lld",&n);
++N;
update(1,N,1,N,(n+t)%D);
}
}
return 0;
}