编译错误 求助
查看原帖
编译错误 求助
443023
chenkuo楼主2023/10/13 15:19
#include<bits/stdc++.h> 
using namespace std;
long long m,d,n,z,k,t,h[200001],a[200001];
char c;
struct asd{
	long long zh,left,right;
}tree[800005];
void build(int left,int right,long long bh){
	tree[bh].left=left;
	tree[bh].right=right;
	tree[bh].zh=-2e8;
	if(left==right){
		h[left]=bh;
		return;
	}
	long long mid=(left+right)/2;
	build(left,mid,bh*2);
	build(mid+1,right,bh*2+1);
}
void add(long long k){
	if(k==1) return;
	if(tree[k/2].zh<tree[k].zh){
		tree[k/2].zh=tree[k].zh;
		add(k/2);
	}
}
long long find(long long l,long long r,long long k){
	if(r<tree[k].left||l>tree[k].right) return -2e8;
	if(l<=tree[k].left&&r>=tree[k].right) return tree[k].zh;
	long long mid=(tree[k].left+tree[k].right)/2;
	return max(find(l,r,k*2),find(l,r,k*2+1));
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>m>>d;
	n=m;
	for(long long i=1;i<=m;i++) a[i]=-2e8;
	build(1,n,1);
	while(m--){
		cin>>c>>k;
		if(c=='A'){
			a[++z]=(k+t)%d;
			tree[h[z]].zh=a[z];
			add(h[z]);
		}
		if(c=='Q'){
			t=find(z-k+1,z,1);
			cout<<t<<endl;
		}
	}
}
2023/10/13 15:19
加载中...