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;
    }
    

      

  • 相关阅读:
    redux和react-redux做简单组件控制
    store(转)
    react+redux开发详细步骤
    rudex 实现流程
    react eject 报错
    react生命周期
    python logging
    hihocoder 1754
    hihocoder_offer收割编程练习赛58
    内存检查
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/7410299.html
Copyright © 2011-2022 走看看