这种全部RE段错误要怎么解决?
#include<bits/stdc++.h>
using namespace std;
int now,tail=0,opt,n,x,temp;
int heap[30010];
void put(int k){
heap[++tail]=k;
now=tail;
while(now>1){
if(heap[now]>heap[now>>1])return;
temp=heap[now];
heap[now]=heap[now>>1];
heap[now>>1]=temp;
now=now>>1;
}
}
int pop(){
int res=heap[1];
heap[1]=heap[tail--];
now=1;
while((now<<1)<=tail){
int next=now<<1;
if (next<tail && heap[next+1]<heap[next])next++;
if(heap[now]<heap[next])return res;
temp=heap[now];
heap[now]=heap[next];
heap[next]=temp;
now=next;
}
}
int main()
{
scanf("%d",&n);
while(n--){
scanf("%d",&opt);
if(opt==1){scanf("%d",&x);put(x);}
if(opt==2){printf("%d\n",heap[1]);}
if(opt==3){pop();}
}
return 0;
}