Poj2051 & amp; UVALive 3135

Source: Internet
Author: User

Poj2051 & amp; UVALive 3135 water question

 

 

Argus
Time Limit:1000 MS   Memory Limit:30000 K
Total Submissions:9716   Accepted:4543

 

Description

A data stream is a real-time, continuous, ordered sequence of items. some examples include sensor data, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web usage logs and telephone call records. likewise, queries over streams run continuously over a period of time and incrementally return new results as new data arrives. for example, a temperature detection system of a factory warehouse may run queries like the following.
Query-1: Every five minutes, retrieve the maximum temperature over the past five minutes.
Query-2: Return the average temperature measured on each floor over the past 10 minutes.

We have developed a Data Stream Management System called Argus, which processes the queries over the data streams. users can register queries to the Argus. argus will keep the queries running over the changing data and return the results to the corresponding user with the desired frequency.

For the Argus, we use the following instruction to register a query:
Register Q_num Period

Q_num (0 <Q_num <= 3000) is query ID-number, and Period (0 <Period <= 3000) is the interval between two consecutive returns of the result. after Period seconds of register, the result will be returned for the first time, and after that, the result will be returned every Period seconds.

Here we have several different queries registered in Argus at once. it is confirmed that all the queries have different Q_num. your task is to tell the first K queries to return the results. if two or more queries are to return the results at the same time, they will return the results one by one in the ascending order of Q_num.

Input

The first part of the input are the register instructions to Argus, one instruction per line. you can assume the number of the instructions will not exceed 1000, and all these instructions are executed at the same time. this part is ended with a line #.

The second part is your task. This part contains only one line, which is one positive integer K (<= 10000 ).

Output

You shoshould output the Q_num of the first K queries to return the results, one number per line.

Sample Input

Register 2004 200Register 2005 300#5

Sample Output

20042005200420042005

Source

Beijing 2004

 

The question pulling function is to learn how to write the priority queue structure. Note that the reload is smaller than the actual priority, because stl is a large root heap by default ..

 

/*** @ Author neko01 * // # pragma comment (linker,/STACK: 102400000,102400000) # include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         Using namespace std; typedef long LL; # define min3 (a, B, c) min (a, min (B, c) # define max3 (a, B, c) max (a, max (B, c) # define pb push_back # define mp (a, B) make_pair (a, B) # define clr (a) memset (, 0, sizeof a) # define clr1 (a) memset (a,-1, sizeof a) # define dbg (a) printf (% d, a) typedef pair
          
            Pp; const double eps = 1e-8; const double pi = acos (-1.0); const int INF = 0x7fffffff; const LL inf = (LL) 1) <61) + 5; struct item {int qnum, period, time; bool operator <(const item & a) const {return time>. time | (time =. time & qnum>. qnum); // here, note that the priority is smaller than the actual time.}; char s [23]; int main () {priority_queue
           
             Q; while (~ Scanf (% s, s) & strcmp (s ,#)! = 0) {item cur; scanf (% d, & cur. qnum, & cur. period); cur. time = cur. period; q. push (cur) ;}int k; scanf (% d, & k); while (k --) {item cur = q. top (); q. pop (); printf (% d, cur. qnum); cur. time + = cur. period; q. push (cur) ;}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.