WA求调
查看原帖
WA求调
821073
chuazen楼主2024/8/1 15:58
#include<bits/stdc++.h>
#define int long long
#define for(i,x,y) for(int i=x;i<=y;i++)
#define N 200005
using namespace std;
inline int read(){
	int f=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f*x;
}
int n,mod,cnt,x,t;
int node[N<<2];
void change_the_tree(int rt,int l,int r,int should,int val){
	if(l==r){
		node[rt]=val;
		return;
	}
	int mid=(l+r)>>1;
	if(mid>=should)change_the_tree(rt*2,l,mid,should,val);
	else change_the_tree(rt*2+1,mid+1,r,should,val);
	node[rt]=max(node[rt*2],node[rt*2+1]);
}
void ask_the_tree(int rt,int l,int r,int l_should,int r_should){
	if(l>r_should||r<l_should)return;
	if(l>=l_should&&r<=r_should){
		t=max(t,node[rt]);
		return;
	}
	int mid=(l+r)>>1;
	ask_the_tree(rt*2,l,mid,l_should,r_should);
	ask_the_tree(rt*2+1,mid+1,r,l_should,r_should);
}
signed main(){
	n=read(),mod=read();
	for(kkkkkkk,1,n){
		char ch;
		while(ch=getchar())if(ch=='A'||ch=='Q')break;
		x=read();
		if(ch=='A'){
			t=(t+x)%mod;
			cnt++;
			change_the_tree(1,1,n,cnt,t);
		}
		else{
			t=LONG_LONG_MIN;
			ask_the_tree(1,1,n,cnt-x+1,cnt);
			printf("%lld\n",t);
		}
	}
	return 0;
}
2024/8/1 15:58
加载中...