站外题求助
  • 板块题目总版
  • 楼主HFLS__Bobby
  • 当前回复6
  • 已保存回复7
  • 发布时间2025/1/23 16:18
  • 上次更新2025/1/23 19:11:36
查看原帖
站外题求助
1526758
HFLS__Bobby楼主2025/1/23 16:18

题目内容在U526586

我写的代码(交在校外只有40分):

#include<bits/stdc++.h>
using namespace std;
const int n=1e6+7;
long long a[n],l=1000001,r=1000000,q;
bool bol=1;
int main()
{
	cin>>q;
	for (int i=1;i<=q;i++)
	{
		int op; 
		int x;
		cin>>op;
		if (op==1)
		{
			if (bol==1)
			{
				cin>>x;
				++r;
				a[r]=x;
			}
			if (bol==0)
			{
				cin>>x;
				--l;
				a[l]=x;
			}
		}
		if (op==2) 
		{
			if (bol==1) 
			{
				cout<<a[r]<<endl;
				r--;
			}
			if (bol==0)
			{
				cout<<a[l]<<endl;
				l++;
			}
		}
		if (op==3)
		{
			if (bol==1)
			{
				bol=0;
			}
			if (bol==0)
			{
				bol=1;
			}
		}
	}
	return 0;
}
2025/1/23 16:18
加载中...