2015 Multi-University Training Contest 5 1007

MZL's simple problem

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
A simple problem
Problem Description
You have a multiple set,and now there are three kinds of operations:
1 x : add number x to set
2 : delete the minimum number (if the set is empty now,then ignore it)
3 : query the maximum number (if the set is empty now,the answer is 0)
 

 

Input
The first line contains a number N (N106),representing the number of operations.
Next N line ,each line contains one or two numbers,describe one operation.
The number in this set is not greater than 109.
 

 

Output
For each operation 3,output a line representing the answer.
 

 

Sample Input
6
1 2
1 3
3
1 3
1 4
3
 

 

Sample Output
3
4
 
题意:三种对集合的操作:1、加入一个数 2、删除最小值 3、求最大值
分析:加入时,维护最大值,删除时如果集合为空,则定义最大值为无穷小
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<algorithm>
#define LL __int64
using namespace std;
const int INF=0x3f3f3f3f;
int n;
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        int opt,x;
        int maxn=-INF;
        int f=0,r=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&opt);
            if(opt==1)
            {
                scanf("%d",&x);
                r++;
                if(x>maxn) maxn=x;
            }
            if(opt==2)
            {
                if(f<r) f++;
                if(f==r) maxn=-INF;
            }
            if(opt==3)
            {
                if(f==r) printf("0\n");
                else printf("%d\n",maxn);
            }
        }
    }
    return 0;
}
View Code

 

posted @ 2015-08-04 22:17  Cliff Chen  阅读(134)  评论(0编辑  收藏  举报