P1165 log analysis and p1165 Log Analysis

Source: Internet
Author: User

P1165 log analysis and p1165 Log Analysis
Description

M Marine company recently wants to collect statistics on the import and export of goods in its warehouse. Currently, the only record they have is a log that records the inbound and outbound container information. This log records two types of operations: the first type of operation is the container warehouse receiving operation, and the container weight of the warehouse receiving; the second type is the container warehouse picking operation. These records are arranged strictly in chronological order. The rules for warehouse receiving and warehouse picking are advanced and later, that is, the containers for each warehouse picking operation are the latest containers for warehouse receiving.

For analysis purposes, analysts randomly inserted several Category 3 operations in the log-query operations. During log analysis, the maximum container weight in the current warehouse must be reported for each query operation.

Input/Output Format Input Format:

Contains N + 1 rows:

The first behavior is a positive integer N, which corresponds to the total number of operations contained in the log.

The next N rows belong to one of the following formats:

Format 1: 0 X // one container warehouse receiving operation. Positive Integer X indicates the weight of the warehouse receiving container.

Format 2: 1 // a container warehouse picking operation (for the time being)

Format 3: 2 // one query operation, requires the analysis program to output the maximum container weight in the current Warehouse

When the Warehouse is empty, you should ignore the warehouse picking operation. When the Warehouse is empty, you should output 0.

Output Format:

The number of output rows equals to the number of query operations in the log. Each behavior is a positive integer that indicates the query result.

Input and Output sample Input example #1:
130 10 220 40 221211212
Output sample #1:
24410
Description

For 20% of the data, N ≤ 10;

For 40% of data, N ≤ 1000;

For 100% of data, there are N ≤ 200000, X ≤ 108.

 

This question is a bit like a monotonous stack?

Because every time we ask for the maximum value, we only need to save the maximum value.

The number smaller than the maximum value is not required

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 const int MAXN=10000001; 7 int n,p,now,maxn; 8 int read(int & n) 9 {10     char c='-';int x=0;11     while(c<'0'||c>'9')c=getchar();12     while(c>='0'&&c<='9')13     {14         x=x*10+(c-48);15         c=getchar();16     }17     n=x;18 }19 int s[MAXN];20 int top=0;21 int main()22 {23     read(n);24     while(n--)25     {26         read(p);27         if(p==0)28         {29             read(now);30             s[++top]=max(now,s[top-1]);31         }32         else if(p==1)33         {34             if(top==0)continue;35             s[top--]=0;    36         }37         else if(p==2)38             printf("%d\n",s[top]);39     }40     return 0;41 }

 

Related Article

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.