Lowest Unique Price(模拟题)

Description

Recently my buddies and I came across an idea! We want to build a website to sell things in a new way.

For each product, everyone could bid at a price, or cancel his previous bid, finally we sale the product to the one who offered the "lowest unique price". The lowest unique price is defined to be the lowest price that was called only once.

So we need a program to find the "lowest unique price", We'd like to write a program to process the customers' bids and answer the query of what's the current lowest unique price.

All what we need now is merely a programmer. We will give you an "Accepted" as long as you help us to write the program.

Input

The first line of input contains an integer T, indicating the number of test cases (T ≤ 60).

Each test case begins with a integer N (1 ≤ N ≤ 200000) indicating the number of operations.

Next N lines each represents an operation.

There are three kinds of operations:

"b x": x (1 ≤ x ≤ 10^6) is an integer, this means a customer bids at price x.

"c x": a customer has canceled his bid at price x.

"q" : means "Query". You should print the current lowest unique price.

Our customers are honest, they won\'t cancel the price they didn't bid at.

Output

 Please print the current lowest unique price for every query ("q"). Print "none" (without quotes) if there is no lowest unique price.

Sample

Input

Copy2 
3 
b 2 
b 2 
q 
12 
b 2 
b 2 
b 3 
b 3 
q 
b 4 
q 
c 4 
c 3 
q 
c 2 
q

Output

Copynone 
none 
4 
3 
2

这题单纯的模拟,跟我在牛客做的一道题雷同,本来想的是什么treap平衡树,后来看到过的人很快,非常意外。

一开始没想到是set要是认真想一想,可能就可以做出来了,但是自己却一意要用vector。

其实也没事自己也的确训练了vector的用法了。长记性了。(就是做得比别人慢,我真不甘心)

先是贴上大佬的代码。(set的使用)

#include <bits/stdc++.h>
using namespace std;

int t,n,x;
int mp[1000101];
int main(){
    scanf("%d",&t);
    while(t --){
        char s[10];
        scanf("%d",&n);
        memset(mp,0,sizeof(mp));
        set<int>S;
        while(n--)
        {
            scanf("%s",s);
            if(s[0]=='b'){
                scanf("%d",&x);
                mp[x]++;
                if(mp[x]==1)
                    S.insert(x);
                else S.erase(x);
            }
            else if(s[0]=='c'){
                scanf("%d",&x);
                mp[x]--;
                if(mp[x]==1)
                    S.insert(x);
                else S.erase(x);

            }
            else{
                if(S.empty())
                    printf("none\n");
                else
                    printf("%d\n",*S.begin());
            }
        }
    }
    return 0;
}

再是我的vector的代码(vector)

#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int main()
{
    int n,m,t,x;
    scanf("%d",&t);
    while(t--){
        vector<int> g;
        scanf("%d",&m);
        while(m--){
            char s[10];
            map<int,int>my;
            scanf("%s",s);
            int a[200000],ans=inf,tot;
            if(s[0]=='q'){
                int flag=0;
                if(g.size()==0){
                    printf("none\n");
                    continue;
                }
                for(int i=0;i<g.size();i+=tot){
        tot=upper_bound(g.begin(),g.end(),g[i])-lower_bound(g.begin(),g.end(),g[i]);
                    if(tot==1){
                        printf("%d\n",g[i]);
                        flag=1;
                        break;
                    }
                }
                if(flag==0){
                    printf("none\n");
                }
            }
            else if(s[0]=='b'){
                  scanf("%d",&x);
                  g.insert(lower_bound(g.begin(),g.end(),x),x);
            }else if(s[0]=='c'){
                  scanf("%d",&x);
                  g.erase(lower_bound(g.begin(),g.end(),x));
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值