hiho week 28 register

Ended

Participants:703

Verdict:Accepted
Score:100 / 100
Submitted:2015-01-11 19:31:16

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<cstdio>
char buf[1<<15],*S=buf,*T=buf,op;
inline char getc(){
    if(S==T)if(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)return 0;
    return*S++;
}
int h[100010],n,i,x,hr;
void ins(int t){int i;for(i=++hr;i!=1&&t>h[i>>1];i>>=1)h[i]=h[i>>1];h[i]=t;}
void dlt(){hr--;int i;
    for(i=1;(i<<1)<=hr&&!(h[hr+1]>=h[i<<1]&&h[hr+1]>=h[i<<1|1]);)
    i<<1!=hr&&h[i<<1|1]>h[i<<1]?(h[i]=h[i<<1|1],i=i<<1|1):(h[i]=h[i<<1],i=i<<1);
    h[i]=h[hr+1];
}
int aa,ch;inline int F(){
    while(ch=getc(),ch<'0'||ch>'9');aa=ch^48;
    while(ch=getc()^48,ch>=0&&ch<=9)aa=(aa<<3)+(aa<<1)+ch;return aa;
}
int main(){
    for(n=F();n--;){
        while(op=getc(),op!='A'&&op!='T');
        if(op=='A')ins(F());
        else printf("%d\n",h[1]),dlt();
    }
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX