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+5;
const double eps = 1e-8;
int T,n,w[N],sum[N<<2],p[N<<2],cnt,m,ret[N];
int k,a[N],mi[N];
int main() {
    while(~scanf("%d",&n)){

        int ans=0;
        mi[0]=1e9+10;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            mi[i]=1e9+10;
        }
        for(int i=1;i<=n;i++){
            mi[i]=min(mi[i-1],a[i]);
        }
        for(int l=n,r=n;l>=1;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 0;
}
时间: 2024-08-02 07:44:02

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

hzau 1205 Sequence Number(二分)

G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A is a ordered set with n numbers ( n > 1 ) which are different from each other. If exist positive integers i , j, ( 1 ≤ i < j ≤ n and A[i] > A[j])

Sequence Number

Sequence 在当前transaction scope之外产生,当事务回滚时,Sequence number 不会回滚. 1,Create Sequence syntax CREATE SEQUENCE [schema_name . ] sequence_name [ AS [ built_in_integer_type | user-defined_integer_type ] ] [ START WITH <constant> ] [ INCREMENT BY <constant

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

当插入值需要从另外一张表中检索得到的时候,如下语法的sql语句已经不能完成该功能:insert into my_table(id, name) values ((select seq_my_table.nextval from dual), ‘runto30′); 会报“ORA-02287: sequence number not allowed here”的错误,可以使用如下语句来完成: insert into my_table(id, name) select seq_my_table.ne

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

InnoDB: The log sequence number in ibdata files does not matchInnoDB的:在ibdata文件的日志序列号不匹配 可能ibdata文件损坏了解决办法如下:在my.cny 的[mysqld]中加入 # Size of each log file in a log group. You should set the combined size # of log files to about 25%-100% of your buffer

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

原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ from:https://blog.csdn.net/a19881029/article/details/38091243 如果你正在读这篇文章,很可能你对TCP“非著名”的“三次握手”或者说“SYN,SYN/ACK,ACK”已经很熟悉了.不幸的是,对很多人来说,对TCP的学习就仅限于此了.尽管年代久远,TCP仍

ORA-02287:此处不允许序号(sequence number not allowed here) 的避免以及强制实现

问题场景一: name FROM (select SEQ_B_LOG_ID.NEXTVAL id , 'elong_deo' name from dual);   问题场景二: into b_authority (id,role_id,authority,remark,url,yn,parent_id,authority_type,log_flag) select SEQ_B_AUTHORITY_ID.NEXTVAL,1, 'admin:role:listRole', '角色分页查询', '/a

[AX]AX2012 Number sequence framework :(三)再谈Number sequence

AX2012的number sequence framework中引入了两个Scope和segment两个概念,它们的具体作用从下面序列的例子说起. 法国/中国的法律要求财务凭证的Journal number包含公司代码和财务期间,比如这样的号码J-20-Jan11-000340,J表上Journal,20代表的是公司代码,Jan11为财务期间,000340才是系统生成的流水号. 在创建Numer sequence的界面上可以选择需要的Scope: Company and fiscal cale

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

问题描述: 研发突然找我,遇到了mysql的 ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction,具体报错如下: org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158) Caused by: java.io .IOException: java.sql.SQLException: Lock wait timeout exceeded;

oracle的sequence序列

Sequence:序列是一个数据对象,可以用来生成唯一的整数.是数据库里独立的对象,不依赖任何表,为oracle所特有.用来自动生成主键值,可以用sequence的地方:inert语句的子查询中,update的set等.创建序列 :Create sequence seqname -increament by 1//每次增长1 -start with 1//从1开始增长 -maxvalue 100//最大值是100,nomaxvalue:不设最大值 -nocycle//一直累加没有循环 -noca