<strong><span style="font-size:18px;">#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int tree[6000010][3],delta[6000010];
int n,m,a[150010],num[150010];
inline void swap(int now)
{
int t;
t=tree[now][1]; tree[now][1]=tree[now][2]; tree[now][2]=t;
}
inline void updata(int now)
{
tree[now][0]=0; tree[now][1]=(now<<1); tree[now][2]=(now<<1)|1;
}
inline void pushdown(int now)
{
if(delta[now])
{
swap(now<<1); swap(now<<1|1);
delta[now<<1]^=1; delta[now<<1|1]^=1;
delta[now]=0;
}
}
void build(int now,int l,int r)
{
if(l==r)
{
tree[now][0]=l;
return;
}
int mid=(l+r)>>1;
build((now<<1),l,mid);
build((now<<1)|1,mid+1,r);
updata(now);
}
void change(int now,int l,int r,int al,int ar)
{
if(al<=l&&r<=ar)
{
swap(now);
delta[now]^=1;
return;
}
int mid=(l+r)>>1;
pushdown(now);
if(al<=mid) change(tree[now][1],l,mid,al,ar);
if(ar>mid) change(tree[now][2],mid+1,r,al,ar);
}
int ask(int now,int l,int r,int al,int ar)
{
if(al<=l&&r<=ar) return tree[now][0];
int mid=(l+r)>>1;
pushdown(now);
if(al<=mid) return ask(tree[now][1],l,mid,al,ar);
if(ar>mid) return ask(tree[now][2],mid+1,r,al,ar);
}
int main()
{
int i,j;
scanf("%d",&n);
for(i=1;i<=n;++i) scanf("%d",&a[i]);
build(1,1,n);
scanf("%d",&m);
for(i=1;i<=m;++i)
{
int x,y;
scanf("%d%d",&x,&y);
change(1,1,n,x,y);
}
for(j=1;j<=n;++j) num[j]=ask(1,1,n,j,j);
for(j=1;j<=n;++j) printf("%d ",a[num[j]]);
return 0;
}</span></strong>