zoukankan      html  css  js  c++  java
  • [luoguP2073] 送花(set)

    传送门

    set

    #include <set>
    #include <cstdio>
    #include <iostream>
    #define LL long long
    
    using namespace std;
    
    struct node
    {
    	LL x, y;
    	node(LL x = 0, LL y = 0) : x(x), y(y) {}
    	inline bool operator < (const node & gg) const
    	{
    		return y < gg.y;
    	}
    };
    
    LL ans1, ans2;
    set <node> s;
    set <node> :: iterator it;
    
    inline int read()
    {
    	int x = 0, f = 1;
    	char ch = getchar();
    	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
    	return x * f;
    }
    
    int main()
    {
    	int x, y, z;
    	while(1)
    	{
    		z = read();
    		if(z == -1) break;
    		if(z == 1)
    		{
    			x = read();
    			y = read();
    			if(s.find(node(x, y)) != s.end()) continue;
    			ans1 += x;
    			ans2 += y;
    			s.insert(node(x, y));
    		}
    		if(z == 3)
    		{
    			if(!s.size()) continue;
    			it = s.begin();
    			ans1 -= (*it).x;
    			ans2 -= (*it).y;
    			s.erase(it);
    		}
    		if(z == 2)
    		{
    			if(!s.size()) continue;
    			it = s.end();
    			it--;
    			ans1 -= (*it).x;
    			ans2 -= (*it).y;
    			s.erase(it);
    		}
    	}
    	printf("%lld %lld
    ", ans1, ans2);
    	return 0;
    }
    

      

  • 相关阅读:
    Title
    Title
    JS淘宝小广告
    JS淘宝浏览商品
    JS隐藏显示图片
    JS图片轮播
    C#连接数据库的方法
    让$(window).scroll()监听事件只执行一次
    axios发delete请求,后台收不到参数;
    .gitignore规则简介
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/7410299.html
Copyright © 2011-2022 走看看