题目内容在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;
}