HDU 5349

MZL‘s simple problem

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 367    Accepted Submission(s): 170

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
(N≤106),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

Source

2015 Multi-University Training Contest 5

开个map就好了。

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>

#define M 100010
using namespace std;
map<__int64, __int64>mp;
std::map<__int64, __int64>::iterator it;
int main()
{
    __int64 n;
    while (scanf("%I64d", &n) != EOF)
    {
        __int64 op, a;
        mp.clear();
        for (int i = 0; i < n; i++)
        {
            scanf("%I64d", &op);
            if (op == 1)
            {
                scanf("%I64d", &a);
                mp[a]++;
            }
            else if (op == 2)
            {
                if (mp.size() == 0)
                    continue;
                it = mp.begin();
                int t = it->first;
                mp[t]--;
                if (mp[t] == 0)
                mp.erase(it);
            }
            else
            {
                if (mp.size() == 0)
                    printf("0\n");
                else
                {
                    it = mp.end();
                    it--;
                    printf("%I64d\n", it->first);
                }
            }
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-27 03:47:01

HDU 5349的相关文章

hdu 5349 MZL&#39;s simple problem

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 numbe

【multiset】hdu 5349 MZL&#39;s simple problem

[multiset]hdu 5349 MZL's simple problem 题目链接:hdu 5349 MZL's simple problem 题目大意 n次操作,插入元素.删除最小元素.查询最大元素并输出. C++STL的multiset的使用 set--多元集合(元素不可重复),multiset--可重复元素的多元集合 多元集合(MultiSets)和集合(Sets)相像,只不过支持重复对象.(具体用法请参照set容器) set和multiset内部是以平衡二叉树实现的: 从内部数据结

hdu 5349 MZL&#39;s simple problem(multiset)

代码: #include<set> #include<cstdio> using namespace std; multiset<int> st; int main() { int n; multiset<int>::iterator it; while(scanf("%d",&n)==1) { st.clear(); int k,num; for(int i=0; i<n; i++) { scanf("%d&qu

hdu - 5349 MZL&#39;s simple problem(解题报告)

A - MZL's simple problem Time Limit:1500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description A simple problem Problem Description You have a multiple set,and now there are three kinds of operations: 1 x : add number

HDU 5349 MZL&#39;s simple problem(优先队列)

MZL's simple problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 776    Accepted Submission(s): 375 Problem Description A simple problem Problem Description You have a multiple set,and now

HDU 5349(2015多校5)-MZL&#39;s simple problem(优先队列)

题目地址:HDU 5349 很水的优先队列就能搞好,只不过注意如果2操作结束后的队列为空,那么Max的值为-inf. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set&

hdu 5349 维护序列 OR Treap

由于只删除最小值和只查询最大值,所以我们只要维护一个maxn和一个size即可,需要注意的是删除到集合空时需要重新将maxn赋值为无穷小. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 6 int main () 7 { 8 int n; 9 while ( scanf("%d", &n) != EOF ) 10

HDU 5349 动态插入删除查询数据-multiset

题意:动态的插入删除查询数据,允许数据重复 分析:一看就是个multiset,直接做.STL大法好. 代码: #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<vector> #include<set> using namespace std; int n; int a; multiset<int> s; i

HDU 5344 MZL&#39;s xor (多校)[补7月28]

MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 249    Accepted Submission(s): 187 Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to k