Problem 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
2
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
Sample Output
none
none
4
3
2
题目描述
b代表增加一个报价,c代表删去这样一个报价,q代表输出只报价一次价值最低的数.
解题思路
水模拟
代码实现
#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);\
cin.tie(0);\
cout.tie(0);
typedef long long ll;
const int maxn = 200000+100;
const int maxm = 1e6+7;
set<int>stt;
int mark[maxm];
int main()
{
IO;
int T;
cin>>T;
char ch;
int value;
while(T--)
{
stt.clear();
memset(mark,0,sizeof(mark));
int n;
cin>>n;
while(n--)
{
cin>>ch;
if(ch=='q')
{
if(stt.empty())
cout<<"none"<<endl;
else
cout<<*stt.begin()<<endl;
}
else if(ch=='b')
{
cin>>value;
mark[value]++;
if(mark[value]==1)
stt.insert(value);
else
stt.erase(value);
}
else if(ch=='c')
{
cin>>value;
mark[value]--;
if(mark[value]==1)
stt.insert(value);
else if(mark[value]==0)
stt.erase(value);
}
}
}
return 0;
}