性 感 TLE 代 码~求调(用栈写的)
查看原帖
性 感 TLE 代 码~求调(用栈写的)
534415
nuo_x楼主2023/8/3 11:08
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll m,d;
stack<ll> s;
stack<ll> t;
int maxx(ll n)
{
	ll maxn=-1145141919810;
	ll cnt=0;
	while(cnt!=n)
	{
		ll x=s.top();
		s.pop();
		t.push(x);
		maxn=max(maxn,x);
		cnt++;
	}
	cnt=0;
	while(cnt!=n)
	{
		ll x=t.top();
		t.pop();
		s.push(x);
		cnt++;
	}
	return maxn;
}
int main()
{
	cin>>m>>d;
	ll tmp=0;
	char c;
	ll x;
	while(m--)
	{
		cin>>c>>x;
		if(c=='A')
		{
			x+=tmp;
			x=(x+d)%d;
			s.push(x);
		}
		else
		{
			tmp=maxx(x);
			cout<<tmp<<endl;
		}
	}
	return 0;
 } 
2023/8/3 11:08
加载中...