CF 319B Psychos in a Line 【单调队列】
维护一个单调下降的队列。
对于每一个人,只需要找到在他前面且离他最近的可以杀掉他的人即可。
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 100005
vector<int> v;
int f[N], n, t, cnt; int main() {
scanf("%d", &n);
memset(f, 0, sizeof(f)); for (int i=0; i<n; i++) {
scanf("%d", &t);
cnt = 0;
if (v.size() == 0) { v.push_back(t); continue; }
while (v.back() < t) {
cnt = max(cnt, f[v.back()]);
v.pop_back();
if (v.size() == 0) break;
}
if (v.size() == 0) { v.push_back(t); continue; }
f[t] = cnt + 1;
v.push_back(t);
} int ans = 0;
for (int i=0; i<n; i++) ans = max(ans, f[i]);
printf("%d\n", ans); return 0;
}
CF 319B Psychos in a Line 【单调队列】的更多相关文章
- Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/p ...
- Codeforces Round #189 (Div. 2) D. Psychos in a Line 单调队列dp
D. Psychos in a Line time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 319B Psychos in a Line(模拟)
There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At eac ...
- 【模板】deque实现单调队列
双端队列deque容器: 关于deque最常用的有这几个函数: 都是成员函数 双端队列模板题:[洛谷]P2952 [USACO09OPEN]牛线Cow Line #include<iostrea ...
- Psychos in a Line CodeForces - 319B (单调栈的应用)
Psychos in a Line CodeForces - 319B There are n psychos standing in a line. Each psycho is assigned ...
- codeforces 251A Points on Line(二分or单调队列)
Description Little Petya likes points a lot. Recently his mom has presented him n points lying on th ...
- 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...
- hdu 3401 单调队列优化DP
Trade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- hdu3530 单调队列
Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
随机推荐
- 数据备份--dump
数据中 心操作大量的数据.当遭到破坏时,这就是一场灾难.这时候需要备份来恢复,及时你又大量的备份数据都没用,备份也肯定不是在浪费时间.你也许很幸运从 来没有经历过数据丢失.但是, 由于这种事情极少发生 ...
- 让JAVA代码跑得更快
本文简单介绍一下在写代码过程中用到的一些让JAVA代码更高效的技巧. 1. 将一些系统资源放在池中(如数据库连接, 线程等) 在standalone的应用中, 数据库连接池可以使用一些开源的连接池 ...
- (转)Decision Tree
Decision Tree:Analysis 大家有没有玩过猜猜看(Twenty Questions)的游戏?我在心里想一件物体,你可以用一些问题来确定我心里想的这个物体:如是不是植物?是否会飞?能游 ...
- The Material Sourcing Process Failed To Create Picking Suggestions in INVTOTRX (文档 ID 2003806.1)
In this Document Symptoms Cause Solution References Applies to: Oracle Inventory Management - Versio ...
- 告诉你一个真实的OpenStack:都谁在用,用来干什么?
告诉你一个真实的OpenStack:都谁在用,用来干什么? OpenStack基金会近日发布的双年调查报告显示,开源云计算软件OpenStack正在进入主流企业市场,但该项目依然面临较难部署和管理的老 ...
- Java [Leetcode 292]Nim Game
问题描述: You are playing the following Nim Game with your friend: There is a heap of stones on the tabl ...
- 学习面试题Day04
1.简述Java派生类中的构造方法如何为父类传递参数. 在Java中,使用super关键字加括号()的形式来为父类的构造方法提供参数,通过参数的数目和类型来决定调用哪个构造方法.如果调用的是父 ...
- Android学习系列(22)--App主界面比较
本文算是一篇漫谈,谈一谈当前几个流行应用的主界面布局,找个经典的布局我们自己也来实现一个.不是为了追求到底有多难,而是为了明白我们确实需要这么做. 走个题,android的UI差异化市场依然很大,依然 ...
- Parallel for loops in .NET C# z
The start index: this is inclusive, i.e. this will be the first index value in the loop The end inde ...
- Print the numbers between 30 to 3000.
Microsoft Interview Question Developer Program Engineers 看到一个题目比较有意思: Print the numbers between 30 t ...