HZAU 1205 Sequence Number(双指针)
题目链接: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(双指针)的更多相关文章
- hzau 1205 Sequence Number(二分)
G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...
- 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 ...
- [crypto][ipsec] 简述ESP协议的sequence number机制
预备 首先提及一个概念叫重放攻击,对应的机制叫做:anti-replay https://en.wikipedia.org/wiki/Anti-replay IPsec协议的anti-replay特性 ...
- Sequence Number
1570: Sequence Number 时间限制: 1 Sec 内存限制: 1280 MB 题目描述 In Linear algebra, we have learned the definit ...
- 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)
原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ from:ht ...
- InnoDB: The log sequence number in ibdata files does not match
InnoDB: The log sequence number in ibdata files does not matchInnoDB的:在ibdata文件的日志序列号不匹配 可能ibdata文件损 ...
- Thread <number> cannot allocate new log, sequence <number>浅析
有时候,你会在ORACLE数据库的告警日志中发现"Thread <number> cannot allocate new log, sequence <number> ...
- ORA-02287: sequence number not allowed here问题的解决
当插入值需要从另外一张表中检索得到的时候,如下语法的sql语句已经不能完成该功能:insert into my_table(id, name) values ((select seq_my_table ...
- [转] 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)
点击阅读原译文 原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ ...
随机推荐
- 【C++ STL】List
1.结构 list使用一个double linked list(双向链表)来管理元素. 2. list 能力 list内部结构和vector或deque截然不同,所以与他们的区别: list不支持随机 ...
- CentOS 7 vim显示中文乱码
使用xshell的时候,发现有时候中文显示有乱码,一开始以为是Xshell没设置好,后来检查了一下xshell<<文件<<属性<<终端:右侧编码,显示的是Unico ...
- Jmeter-8-FTP测试
1. 此处要深刻理解FTP的用法. 2. Get的时候填写的Remote File 路径/, 此处是相对路径. 实际为/home/user/ 3. Local file 此处要写到具体的文件. 4. ...
- 省队集训 Day3 吴清华
[题目大意] 给网格图,共有$n * n$个关键节点,横向.纵向距离均为$d$,那么网格总长度和宽度均为$(n+1) * d + 1$,最外围一圈除了四角是终止节点.要求每个关键节点都要通过线连向终止 ...
- bzoj 1731: [Usaco2005 dec]Layout 排队布局 ——差分约束
Description 当排队等候喂食时,奶牛喜欢和它们的朋友站得靠近些.FJ有N(2<=N<=1000)头奶牛,编号从1到N,沿一条直线站着等候喂食.奶牛排在队伍中的顺序和它们的编号是相 ...
- Android控件——监听按钮的点击事件
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAroAAAFTCAIAAABZPDiZAAAgAElEQVR4nOy9918UWfb///1jdu2uBs
- %和format 细说
Python中格式化字符串目前有两种阵营:%和format,我们应该选择哪种呢? 自从Python2.6引入了format这个格式化字符串的方法之后,我认为%还是format这根本就不算个问题.不信你 ...
- [New learn] 网络基础-apache本地服务搭建(支持php)
1.简介 无网不利,无网不胜.对于移动应用来说离开网络那和咸鱼有什么分别?所以对于开发者来说更要学习好网络开发的技术. 2.搭建apache本地服务器 1.在finder中显示影藏的用户文件夹 fin ...
- 去掉a标签的虚线框,避免出现奇怪的选中区域
a{blr:expression(this.onFocus=this.blur())}/*去掉a标签的虚线框,避免出现奇怪的选中区域*/
- FTP webReq.ContentType异常的处理
FtpWebRequest webReq; webReq = (FtpWebRequest)FtpWebRequest.Create(new Uri(updateFileUrl)); FtpWebRe ...