鸣谢 $15owzly1$。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

x=0; char c=getchar();
while(c<'0'||'9'<c)c=getchar();
while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48); c=getchar();}
}

const int N=500050;

int n,m;
int a[N],b[N];
int inf=1e9+1,fni=-1e9-1;

int solve(int La,int Ra,int Lb,int Rb){
int l=La,r=Ra,mid;
int len=(Ra+Rb-La-Lb+2)>>1,pos;
swap(b[Lb-1],fni); swap(b[Rb+1],inf);
while(l<=r){
mid=(l+r)>>1;
pos=Lb+len-(mid-La+1);
if(pos+1<Lb){r=mid-1; continue;}
if(pos-1>Rb){l=mid+1; continue;}
if(b[pos]<=a[mid]&&a[mid]<=b[pos+1]){
swap(b[Lb-1],fni); swap(b[Rb+1],inf);
return a[mid];
}
if(b[pos]>a[mid])l=mid+1;
else r=mid-1;
}
swap(b[Lb-1],fni); swap(b[Rb+1],inf);

l=Lb; r=Rb;
swap(a[La-1],fni); swap(a[Ra+1],inf);
while(l<=r){
mid=(l+r)>>1;
pos=La+len-(mid-Lb+1);
if(pos+1<La){r=mid-1; continue;}
if(pos-1>Ra){l=mid+1; continue;}
if(a[pos]<=b[mid]&&b[mid]<=a[pos+1]){
swap(a[La-1],fni); swap(a[Ra+1],inf);
return b[mid];
}
if(a[pos]>b[mid])l=mid+1;
else r=mid-1;
}
swap(a[La-1],fni); swap(a[Ra+1],inf);
}

int main(){
//	freopen("median.in","r",stdin);
//	freopen("median.out","w",stdout);
int opt,x,y,l,r;
while(m--){
if(opt==1){if(x)b[y]=l;else a[y]=l;}
else {
printf("%d\n",solve(x,y,l,r));
}
}
return 0;
}