ZCMU—B
来源:互联网 发布:数据挖掘要求英语吗 编辑:程序博客网 时间:2024/05/16 07:32
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 ≤ 106) 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表示询问当前最小价格
并且有个条件,当且只当某个价格x在队列中出现的次数为1的时候才被认为是可行的价格
set+判重...开考虑10^6所以不开一般数组用map...当然用一般数组也不会炸内存..但是memset的初始化速度可能会导致tle..
【代码】
#include <iostream>#include <set>#include <cstdio>#include <map>#include <algorithm>#include <cstring>using namespace std;char s[10];map<int,int>vis;set<int>a; int main(){int pp;scanf("%d",&pp);while (pp--){vis.clear();a.clear();int n,x;scanf("%d",&n);for (int i=0;i<n;i++){scanf("%s",s);if (s[0]=='b'){scanf("%d",&x);vis[x]++;if (vis[x]==1) a.insert(x);else a.erase(x);}elseif (s[0]=='c'){scanf("%d",&x);vis[x]--;if (vis[x]==1) a.insert(x);if (vis[x]==0) a.erase(x);}else{if (a.empty()) printf("none\n");elseprintf("%d\n",*a.begin());}}}}
- ZCMU—B
- ZCMU-校赛B-1777
- ZCMU新人训练赛B
- ZCMU新人训练赛B
- ZCMU-1861-zbj的a+b
- ZCMU-1107: 迟来的A+B
- ZCMU—1678
- ZCMU—1605
- ZCMU—1067
- ZCMU—1607
- ZCMU—1069
- ZCMU—1611
- ZCMU—1606
- ZCMU—1774
- ZCMU—1766
- ZCMU—1752
- ZCMU—1724
- ZCMU—1623
- Android6.0权限适配
- Java多线程基础
- 用JavaScript实现图片剪切效果
- android_File
- android google 分屏 多窗口 按home键界面错乱故障分析(一)分屏的整个流程分析
- ZCMU—B
- Java中进程与线程
- 华为oj初级 查找组成一个偶数最接近的两个素数
- Linux Kernel设备驱动模型之总线查找设备
- 计算机视觉领域的一些牛人博客,研究机构等的网站链接
- maven中报错“Missing artifact jdk.tools:jdk.tools:jar:1.8”
- DNS服务器及DDNS配置
- 【leetcode】sqrt
- EditPlus 格式化 Unicode,编辑properties