求助P1198
  • 板块灌水区
  • 楼主liuyuannb
  • 当前回复4
  • 已保存回复4
  • 发布时间2022/7/19 11:31
  • 上次更新2023/10/27 19:34:46
查看原帖
求助P1198
449548
liuyuannb楼主2022/7/19 11:31

P1198求助,十个点全部MLE

#include<bits/stdc++.h>
using namespace std;
long long f[4000001],cnt=0,t=0;
long long zz(long long x)
{
	return x<<1;
}
long long yz(long long x)
{
	return x<<1|1;
}
void gx(long long rt)
{
	f[rt]=max(f[zz(rt)],f[yz(rt)]);
}
void cr(long long ans,long long x,long long l,long long r,long long rt)
{
	if(l==r)
	{
		f[rt]=ans;
		return ;
	}
	long long m((l+r)>>1);
	if(x<=m)
	  cr(ans,x,l,m,zz(rt));
	else
	  cr(ans,x,m+1,r,yz(rt));
	gx(rt);
}
long long cx(long long L,long long R,long long l,long long r,long long rt)
{
	if(L<=l&&r<=R)
	{
		return f[rt];
	}
	long long m((l+r)>>1),ans=-(1<<62);
	if(L<=m)
	  ans=max(cx(L,R,l,m,zz(rt)),ans);
	if(m<R)
	  ans=max(cx(L,R,m+1,r,yz(rt)),ans);
	return ans;
}
int main()
{
    long long m,d,x;
    cin>>m>>d;
    while(m)
    {
    	m--;
    	char c;
    	cin>>c>>x;
    	if(c=='A')
    	{
    		cnt++;
    		cr((x+t)%d,cnt,1,m,1);
		}
		if(c=='Q')
		{
			t=cx(cnt-x+1,cnt,1,m,1);
			cout<<t<<endl;
		}
	}
	return 0;
}
2022/7/19 11:31
加载中...