救救孩子吧,用单调队列写全WA,心态崩了
查看原帖
救救孩子吧,用单调队列写全WA,心态崩了
377511
果圆楼主2021/8/17 16:59
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=200010;
typedef long long ll;
ll t,a[N],mod;
int q[N],u,hh=1,tt,n;
int main()
{
	cin>>n>>mod;
	while(n--)
	{
		char c;
		ll x;
		cin>>c;
		cin>>x;
		if(c=='A')
		{
			u++;
			a[u]=(x+t)%mod;
			if(tt==0) q[++tt]=u;
			else if(tt==1)
			{
				if(a[q[tt]]>a[u]) q[++tt]=u;
				else q[tt]=u;
			}
			else
			{
				int l=hh,r=tt;
				while(l<r)
				{
					int mid=(l+r)>>1;
					if(a[q[mid]]>a[u]) l=mid+1;
					else r=mid;
				}
				tt=l;
				q[tt]=u;
			}
		}
		else if(c=='Q')
		{
			if(tt==1)
			{
				t=a[q[tt]];
			}
			else
			{
				int k=u-x+1;
				int l=hh,r=tt;
				while(l<r)
				{
					int mid=(l+r)>>1;
					if(q[mid]<k) l=mid+1;
					else r=mid;
				}
				t=a[q[l]];
			}
			printf("%lld\n",t);
		}
	}
	return 0;
}
2021/8/17 16:59
加载中...