跳到正文

个人记录

P1804

_yanny_约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年7月24日
更新
2026年7月24日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,a[300005],m,l=100001,r;
bool ok;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen("seq.in","r",stdin);
//	freopen("seq.out","w",stdout);
	cin>>n;
	r=l+n-1;
	for(int i=l;i<=r;i++)cin>>a[i];
	cin>>m;
	while(m--){
		int f;
		int x;
		cin>>f;
		if(f==1){
			cin>>x;
			if(ok){
				a[++r]=x;
			}
			else a[--l]=x;
		}
		else if(f==2){
			cin>>x;
			if(!ok){
				a[++r]=x;
			}
			else a[--l]=x;
		}
		else ok=!ok;
	}
	if(ok){
		for(int i=r;i>=l;i--){
			cout<<a[i]<<" ";
		}
	}
	else{
		for(int i=l;i<=r;i++){
			cout<<a[i]<<" ";
		}
	}
	return 0;
}
原文