NEU OJ 1644 Median I

优先级队列

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
int n;
int main()
{
    while(~scanf("%d",&n))
    {
        int tot=0;
        priority_queue<int>Q;
        while(n--)
        {
            int x;
            scanf("%d",&x);
            if(x==1)
            {
                int u;
                scanf("%d",&u);
                tot++;
                Q.push(u);
            }
            else if(x==2)
            {
                if(tot==0) printf("-1\n");
                else
                {
                    int r=tot-(tot/2+1);
                    while(r--) Q.pop();
                    int h=Q.top();
                    printf("%d\n",h);
                    tot=(tot/2+1);
                }
            }
        }
    }
    return 0;
}

 

posted @ 2015-08-12 19:09  Fighting_Heart  阅读(190)  评论(0编辑  收藏  举报