Educational Codeforces Round 27 D. Driving Test

 

单调栈

 

题意看了半天。。。

 

 1     #include <cstdio>
 2     #include <cstdlib>
 3     #include <cmath>
 4     #include <cstring>
 5     #include <string>
 6     #include <algorithm>
 7     #include <iostream>
 8     using namespace std;
 9     #define ll long long
10      
11     const int maxn=2e5+10;
12     const int inf=1e9;
13      
14     int sum1,tot1;
15     int f[maxn],g;
16      
17     int main()
18     {
19         int n,a,b,i,j,v;
20         scanf("%d",&n);
21         for (i=1;i<=n;i++)
22         {
23             scanf("%d",&a);
24             if (a==1 || a==3)
25                 scanf("%d",&b);
26      
27             if (a==4)
28                 tot1=0;
29             else if (a==6)
30                 tot1++;
31             else if (a==2)
32                 sum1+=tot1,tot1=0;
33      
34             if (a==5)
35                 g=0;
36             else if (a==1)
37             {
38                 v=b;
39                 while (g>0 && f[g]<v)
40                     g--,sum1++;
41             }
42             else if (a==3)
43             {
44                 if (b<v)
45                     sum1++;
46                 else
47                     f[++g]=b;
48             }
49         }
50         printf("%d",sum1);
51         return 0;
52     }

 

posted @ 2019-06-29 21:50  congmingyige  阅读(120)  评论(0编辑  收藏  举报