Sixth session of Shandong Province ACM Contest b Lowest Unique Price

Source: Internet
Author: User
Lowest Unique Price Time limit:1000ms Memory limit:65536k in doubt. Dot here ^_^ Title DescriptionRecently my buddies and I came across an idea! We want to build a website to sell things in a new. For each product, everyone could bid at a price, or cancel his previous bid, and finally we sale the product to the one who fered the "lowest unique price". The lowest unique price are defined to being the lowest price, 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 an Swer the query of what's the lowest unique price. All and we need now is merely a programmer. We'll give you a "Accepted" as long as you help us to write the program. inputThe 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 is three kinds of operations: "B X": X (1≤x≤10 6) was an integer, this means a customer bids at price x. "C X": A customer has canceled he bid at Price x. "Q": means "Query". You should print the current lowest unique price. Our customers is honest, they won\ ' t cancel the price they didn ' t-bid at. OutputPlease print the current lowest unique price for every query ("Q"). Print "None" (without quotes) If there is the no lowest unique price. Sample Input
2 
3 
B 2 
b 2 
q 
B 2 
B 2 
B 3 
b 3 
q 
b 4 
q 
C 4 
c 3 
q< C17/>c 2 
Q
Sample Output
None 
None 
4 
3 
2
solving using Set and map Test Instructions: Perform three operations, add bids, delete bids, and minimize bids with an output count of 1

#include <cstdio> #include <set> #include <map> using namespace std;
    int main () {set<int> myset;
    Map<int, int> Mymap;
    char c;
    int T, n, X;
    scanf ("%d", &t);   while (t--) {myset.clear ();
        Delete all elements in the Set container mymap.clear ();
        scanf ("%d", &n);
            for (int i = 0; i < n; i++) {scanf ("%c", &c);
                if (c = = ' B ') {scanf ("%d", &x);   Myset.insert (x);
                Inserts a value into the Set container mymap[x]++;  if (Mymap[x] > 1) myset.erase (x);
                More than one, delete this element} else if (c = = ' C ') {scanf ("%d", &x);
                mymap[x]--;
                if (mymap[x] = = 1) myset.insert (x);
            else if (mymap[x] = = 0) myset.erase (x); } else{if (!myset.empty ()) printf ("%d\n", *myset.begin ());
            If not empty, output the first element else printf ("none\n");
}}} return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.