题目链接:http://acm.hzau.edu.cn/problem.php?id=1205

【题意】给你一串数,要求你找到两个数a[i],a[j],使得a[i]<=a[j]且j>=i且j-i最大。

【分析】预处理1~i的最小值,然后从右往左双指针,维护右端点>左端点,如果右端点<1~L的最小值,则移动右端点。

#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int N = 1e5+;
const double eps = 1e-;
int T,n,w[N],sum[N<<],p[N<<],cnt,m,ret[N];
int k,a[N],mi[N];
int main() {
while(~scanf("%d",&n)){ int ans=;
mi[]=1e9+;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
mi[i]=1e9+;
}
for(int i=;i<=n;i++){
mi[i]=min(mi[i-],a[i]);
}
for(int l=n,r=n;l>=;l--){
if(mi[l]>a[r]){
while(a[r]<mi[l]){
r--;
}
ans=max(ans,r-l);
}
else {
ans=max(ans,r-l);
}
}
printf("%d\n",ans);
}
return ;
}

HZAU 1205 Sequence Number(双指针)的更多相关文章

  1. hzau 1205 Sequence Number(二分)

    G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...

  2. mysql oom之后的page 447 log sequence number 292344272 is in the future

    mysql oom之后,重启时发生130517 16:00:10 InnoDB: Error: page 447 log sequence number 292344272InnoDB: is in ...

  3. [crypto][ipsec] 简述ESP协议的sequence number机制

    预备 首先提及一个概念叫重放攻击,对应的机制叫做:anti-replay https://en.wikipedia.org/wiki/Anti-replay IPsec协议的anti-replay特性 ...

  4. Sequence Number

    1570: Sequence Number 时间限制: 1 Sec  内存限制: 1280 MB 题目描述 In Linear algebra, we have learned the definit ...

  5. 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

    原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ from:ht ...

  6. InnoDB: The log sequence number in ibdata files does not match

    InnoDB: The log sequence number in ibdata files does not matchInnoDB的:在ibdata文件的日志序列号不匹配 可能ibdata文件损 ...

  7. Thread <number> cannot allocate new log, sequence <number>浅析

    有时候,你会在ORACLE数据库的告警日志中发现"Thread <number> cannot allocate new log, sequence <number> ...

  8. ORA-02287: sequence number not allowed here问题的解决

    当插入值需要从另外一张表中检索得到的时候,如下语法的sql语句已经不能完成该功能:insert into my_table(id, name) values ((select seq_my_table ...

  9. [转] 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

    点击阅读原译文 原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ ...

随机推荐

  1. select + 回调 + 事件循环

    #1. epoll并不代表一定比select好 # 在并发高的情况下,连接活跃度不是很高, epoll比select # 并发性不高,同时连接很活跃, select比epoll好 #通过非阻塞io实现 ...

  2. 注意for循环中变量的作用域

    for e in collections: pass 在for 循环里, 最后一个对象e一直存在在上下文中.就是在循环外面,接下来对e的引用仍然有效. 这里有个问题容易被忽略,如果在循环之前已经有一个 ...

  3. 【bzoj3387-跨栏训练】线段树+dp

    我们可以想到一个dp方程:f[i][0]表示当前在i个栅栏的左端点,f[i][1]表示在右端点. 分两种情况: 第一种:假设现在要更新线段gh的左端点g,而它下来的路径被ef挡住了,那么必定是有ef来 ...

  4. Spring理论基础-面向切面编程

    AOP是Aspect-Oriented Programming的缩写,中文翻译是面向切面编程.作为Spring的特征之一,是要好好学习的. 首先面向切面编程这个名称很容易让人想起面向对象编程(OOP) ...

  5. C# 类内部添加索引器

    public class PersonTable : Indexer { public int xuhao { get; set; } public string name { get; set; } ...

  6. javascript 事件绑定

    一.最简单和向后兼容性最好的事件绑定方法是把事件绑定到元素标识的属性.事件属性名称由事件类型外加一个“on”前缀构成.这些属性也被称为事件处理器 <INPUT TYPE="text&q ...

  7. Spring的BeanFactory体系结构(一)

    本文使用的代码是: Spring 3.0 接 触Spring也有很长一段时间了.但是,每次都是直接使用Spring直接提供的API,时间久了,自然也会想探索Spring里面的奥秘.今天上 午,整理出了 ...

  8. [Leetcode Week16]Range Sum Query - Mutable

    Range Sum Query - Mutable 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/range-sum-query-mutable/de ...

  9. python基础===理解Class的一道题

    解题如下: from random import randint class Die(): def __init__(self,sides=6): self.sides = sides def rol ...

  10. 使用cmd(黑窗口)敲命令使用远程数据库

    C:\Users\gzz>mysql -h 10.27.104.176 -u root -p mysql