hdu5344MZL's simple problem stl set

// 1 x 在set中加x
//2 删除集合中的最小元素
//3 输出集合的最大元素
#include<cstdio>
#include<cstring>
#include<iostream>
#include<set>
using namespace std ;
const int maxn = 1e6+10 ;
multiset<int> ms ;
int main()
{
    int n ;
    multiset<int>::iterator it ;
    while(~scanf("%d" , &n))
    {
        ms.clear() ;
        while(n--)
        {
            int op , x ;
            scanf("%d" , &op) ;
            if(op == 1)
            {
                scanf("%d" , &x) ;
                ms.insert(x) ;
            }
            else if(op == 2)
            {
                if(!ms.size())continue ;
                ms.erase(ms.begin()) ;
            }
            else
            {
                if(!ms.size())puts("0") ;
                else
                {
                    it = ms.end() ;
                    it-- ;
                    printf("%d\n" , *(it)) ;
                }
            }
        }
    }
}

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

hdu5344MZL's simple problem stl set

时间: 2024-10-16 07:47:11

hdu5344MZL's simple problem stl set的相关文章

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内部是以平衡二叉树实现的: 从内部数据结

mutiset HDOJ 5349 MZL&#39;s simple problem

题目传送门 1 /* 2 这题可以用stl的mutiset容器方便求解,我对这东西不熟悉,TLE了几次,最后用读入外挂水过. 3 题解有O(n)的做法,还以为我是侥幸过的,后来才知道iterator it写在循环内才超时了,囧! 4 */ 5 /************************************************ 6 Author :Running_Time 7 Created Time :2015-8-4 12:10:11 8 File Name :G.cpp 9

NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~

链接:click here 题意: A Simple Problem 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved pr

E - A Simple Problem with Integers

#include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; #define N 100002 struct node { int l,r; long long lz,w; }q[4*N]; void pushup(int rt) { q[rt].w=q[rt*2].w+q[rt*2+1].w; } void pushdo

POJ 3468 A Simple Problem with Integers

链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 77302 Accepted: 23788 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two ki

poj 3468 A Simple Problem with Integers(线段树+区间更新+区间求和)

题目链接:id=3468http://">http://poj.org/problem? id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 83959   Accepted: 25989 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. Yo

poj3468 A Simple Problem with Integers 线段树区间更新

A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 97722   Accepted: 30543 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of

POJ 3468 A Simple Problem with Integers(树状数组区间更新)

A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 97217   Accepted: 30358 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of