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     }

原文地址:https://www.cnblogs.com/cmyg/p/11108010.html

时间: 2025-01-17 22:09:47

Educational Codeforces Round 27 D. Driving Test的相关文章

Educational Codeforces Round 27 C

题意:给出一些节目的播放区间,问有2个电视的你是否可以看完全部节目,不可重合 思路:模拟 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 struct node{ 5 int l,r; 6 }a[200005]; 7 bool cmp(node p,node q){ 8 return p.l<q.l; 9 } 10 int main(){ 11 int n; 12 cin>>n; 13 for(int i=1;i<

Educational Codeforces Round 27

A. Chess Tourney Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obvio

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Educational Codeforces Round 26 D. Round Subset(dp)

题目链接:Educational Codeforces Round 26 D. Round Subset 题意: 给你n个数,让你选其中的k个数,使得这k个数的乘积的末尾的0的个数最大. 题解: 显然,末尾乘积0的个数和因子2和因子5的个数有关. 然后考虑dp[i][j]表示选i个数,当前因子5的个数为j时,能得到因子2最多的为多少. 那么对于每个数,记录一下因子2和5的个数,做一些01背包就行了. 1 #include<bits/stdc++.h> 2 #define mst(a,b) me

Educational Codeforces Round 23 F. MEX Queries(线段树)

题目链接:Educational Codeforces Round 23 F. MEX Queries 题意: 一共有n个操作. 1.  将[l,r]区间的数标记为1. 2.  将[l,r]区间的数标记为0. 3.  将[l,r]区间取反. 对每个操作,输出标记为0的最小正整数. 题解: hash后,用线段树xjb标记一下就行了. 1 #include<bits/stdc++.h> 2 #define ls l,m,rt<<1 3 #define rs m+1,r,rt<&l

Educational Codeforces Round 23 D. Imbalanced Array(单调栈)

题目链接:Educational Codeforces Round 23 D. Imbalanced Array 题意: 给你n个数,定义一个区间的不平衡因子为该区间最大值-最小值. 然后问你这n个数所有的区间的不平衡因子和 题解: 对每一个数算贡献,a[i]的贡献为 当a[i]为最大值时的 a[i]*(i-l+1)*(r-i+1) - 当a[i]为最小值时的a[i]*(i-l+1)*(r-i+1). 计算a[i]的l和r时,用单调栈维护.具体看代码,模拟一下就知道了. 然后把所有的贡献加起来.

Educational Codeforces Round 25 F. String Compression(kmp+dp)

题目链接:Educational Codeforces Round 25 F. String Compression 题意: 给你一个字符串,让你压缩,问压缩后最小的长度是多少. 压缩的形式为x(...)x(...)  x表示(...)这个出现的次数. 题解: 考虑dp[i]表示前i个字符压缩后的最小长度. 转移方程解释看代码,这里要用到kmp来找最小的循环节. 当然还有一种找循环节的方式就是预处理lcp,然后通过枚举循环节的方式. 这里我用的kmp找的循环节.复杂度严格n2. 1 #inclu

Educational Codeforces Round 23 E. Choosing The Commander (trie)

题目链接: Educational Codeforces Round 23 E. Choosing The Commander 题意: 一共有n个操作. 1.  插入一个数p 2.  删除一个数p 3.  询问有多少个数 使得 x^p<l 题解: 对于前两种操作用01trie就能解决. 对于对三个操作,我们考虑在trie上搜索. 1.  当l的bit位是1时,那边bit位是p的字数全部的数都会小于l,(因为p^p=0) 2.  当l的bit为是0时,那边只能向bit位是p的子树中搜. 这样算下来

Educational Codeforces Round 22 E. Army Creation(主席树)

题目链接:Educational Codeforces Round 22 E. Army Creation 题意: 给你n个数和一个数k,然后有q个询问. 每个询问 有一个区间[l,r],问你这个区间内在满足每一种数不超过k的情况下,最大能选多少个数出来. 强制在线. 题解: 一看就要用到主席树,和主席数求区间内有多少不同的数的个数处理方法相同. 依次将每个数插入,当这个数出现的个数等于k了,就把最前面的那个数删掉. 然后询问就访问root[r]就行了. 第一次写完数据结构没有调试一遍过样例,一