0ptsWA sub1过了 求调 玄关
查看原帖
0ptsWA sub1过了 求调 玄关
773386
Error303楼主2024/11/24 21:19
#include<bits/stdc++.h>
#define gc() getchar()
#define pc(x) putchar((x))
#define db double
#define ll long long
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define mid(l,r) (((l)+(r))>>1)
#define fr(i,j,k) for(int i=(j);i<=(k);i++)
#define file(dict) freopen(#dict".in","r",stdin),freopen(#dict".out","w",stdout)
#define int long long

using namespace std;
//char *p1,*p2,buf[100000];
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
const int INF=0x3f3f3f3f,ho=114514,mo=1919810,N=2e5+5;
int m,d,num,t=0;
struct Tree{
	int l,r,maxn;
}tr[N<<2];

inline int read(){
	int x=0,f=1;
	char ch=gc();
	while(ch<'0'||ch>'9'){
		if(ch=='-')	f=-1;
		ch=gc();
	}
	while(ch>='0'&&ch<='9')
		x=(x<<3)+(x<<1)+(ch-'0'),ch=gc();
	return x*f;
}

inline void write(int x){
	if(x<0){x=-x;pc('-');}
	if(x>9)	write(x/10);
	pc(x%10+'0');
}

void build(int p,int l,int r){
//	cout << p << " " << l << " " << r << "\n";
//	if ((double)clock() / CLOCKS_PER_SEC >= 0.97) exit(0);
	tr[p].l=l;tr[p].r=r;
	if(l==r){tr[p].maxn=-INF;return ;}
	build(ls(p),l,mid(l,r));
	build(rs(p),mid(l,r)+1,r);
	tr[p].maxn=max(tr[ls(p)].maxn,tr[rs(p)].maxn);
	return ;
}

void change(int p,int i,int k){
	if(tr[p].l==tr[p].r){tr[p].maxn=k;return ;}
	int md=mid(tr[p].l,tr[p].r);
	if(i<=md)	change(ls(p),i,k);
	else	change(rs(p),i,k);
	tr[p].maxn=max(tr[ls(p)].maxn,tr[rs(p)].maxn);
	return ;
}

int ask(int p,int l,int r){
	if(tr[p].l>=l&&tr[p].r<=r)	return tr[p].maxn;
	if(tr[p].l>r||tr[p].r<l)	return -INF;
	int ans=-INF;
	if(tr[ls(p)].r>=l)	ans=max(ans,ask(ls(p),l,r));
	if(tr[rs(p)].l<=r)	ans=max(ans,ask(rs(p),l,r));
	return ans;
}

signed main(){
//	ios::sync_with_stdio(0);
//	file();
	m=read();d=read();
	build(1,1,2e5);
	while(m--){
		char ch=gc();
		ll n=read();
		if(ch=='A'){n=(n+t)%d;change(1,++num,n);}
		else{
			t=ask(1,num-n+1,num);
			write(t);pc(10);
		}
	}
	return 0;
}
2024/11/24 21:19
加载中...