预处理last[i]表示以第i个开始,的合法后缀。

pre[i]表示以第i个结尾,的合法前缀。

那么每一个数a[i],肯定是一个合法后缀last[i] + 一个合法前缀,那么合法前缀的数字要小于a[i],并且最大,bit维护小于等于val的最大值即可。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e4 + ;
int c[maxn];
int lowbit(int x) {
return x & (-x);
}
void upDate(int pos, int val) {
while (pos <= maxn - ) {
c[pos] = max(c[pos], val);
pos += lowbit(pos);
}
}
int ask(int pos) {
int ans = ;
while (pos) {
ans = max(ans, c[pos]);
pos -= lowbit(pos);
}
return ans;
}
int a[maxn];
int n;
int last[maxn], pre[maxn];
void work() {
memset(c, , sizeof c);
for (int i = ; i <= n; ++i) cin >> a[i];
last[n] = ;
for (int i = n - ; i >= ; --i) {
if (a[i] < a[i + ]) {
last[i] = last[i + ] + ;
} else last[i] = ;
}
pre[] = ;
for (int i = ; i <= n; ++i) {
if (a[i] > a[i - ]) {
pre[i] = pre[i - ] + ;
} else pre[i] = ;
}
int ans = ;
for (int i = ; i <= n; ++i) {
ans = max(ans, last[i] + ask(a[i] - ));
upDate(a[i], pre[i]);
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
IOS;
while (cin >> n) work();
return ;
}

csu 1551: Longest Increasing Subsequence Again BIT + 思维的更多相关文章

  1. CSU - 1551 Longest Increasing Subsequence Again —— 线段树/树状数组 + 前缀和&后缀和

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 题意: 给出一段序列, 删除其中一段连续的子序列(或者不删), 使得剩下的序列 ...

  2. CSU 1551 Longest Increasing Subsequence Again(树状数组 或者 LIS变形)

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 升级版:Uva 1471 题意: 让你求删除一段连续的子序列之后的LIS. 题 ...

  3. CSUOJ 1551 Longest Increasing Subsequence Again

    1551: Longest Increasing Subsequence Again Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 75  Solved ...

  4. 300最长上升子序列 · Longest Increasing Subsequence

    [抄题]: 往上走台阶 最长上升子序列问题是在一个无序的给定序列中找到一个尽可能长的由低到高排列的子序列,这种子序列不一定是连续的或者唯一的. 样例 给出 [5,4,1,2,3],LIS 是 [1,2 ...

  5. 673. Number of Longest Increasing Subsequence最长递增子序列的数量

    [抄题]: Given an unsorted array of integers, find the number of longest increasing subsequence. Exampl ...

  6. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  7. [tem]Longest Increasing Subsequence(LIS)

    Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...

  8. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  9. Leetcode 300 Longest Increasing Subsequence

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

随机推荐

  1. (转)Java经典设计模式(1):五大创建型模式(附实例和详解)

    原文出处: 小宝鸽 一.概况 总体来说设计模式分为三大类: (1)创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. (2)结构型模式,共七种:适配器模式.装饰器模式.代 ...

  2. Oracle在Java中事物管理

    对于 对数据库中的数据做dml操作时,能够回滚,这一事物是很重要的 下面例子是对数据库中数据进行修改 package com.demo.oracle; import java.sql.Connecti ...

  3. 基于logstash+elasticsearch+kibana的日志收集分析方案(Windows)

    一 方案背景     通常,日志被分散的储存不同的设备上.如果你管理数十上百台服务器,你还在使用依次登录每台机器的传统方法查阅日志.这样是不是感觉很繁琐和效率低下.开源实时日志分析ELK平台能够完美的 ...

  4. java运行Linux命令

    <%@ page language="java" import="java.util.*,java.io.*" pageEncoding="UT ...

  5. codeforces 702C C. Cellular Network(水题)

    题目链接: C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input st ...

  6. BZOJ_5418_[Noi2018]屠龙勇士_exgcd+excrt

    BZOJ_5418_[Noi2018]屠龙勇士_exgcd+excrt Description www.lydsy.com/JudgeOnline/upload/noi2018day2.pdf 每次用 ...

  7. 工艺(SAM)

    传送门 用SAM可以非常轻松的解决问题. 只要把原串向SAM中插入两次,之后直接从\(t_0\)状态开始每次贪心跑最小就可以了. 因为这个题要用map,所以之前取begin即可. // luogu-j ...

  8. 如何使用 Jmeter 发送 Json 请求

    公司最近有一个项目,需要持续发送大量的 Json 请求到服务器,从而测试服务器可靠性. 我就发送 Json 请求部分发布这个博客. 一般来说, Json 请求的数据都保存到 CSV 文件中,然后使用 ...

  9. MongoDB 3.2复制集单节点部署(四)

    MongoDB在单节点中也可以做复制集,但是仅限于测试实验,最大的好处就是部署方便快速,可以随便添加新节点,节省资源.在这里我使用的是MongoDB 3.2版本进行复制集实验(但MongoDB配置文件 ...

  10. Linux下启动mongodb

    完成安装mongodb(略) 创建数据目录: # mkdir /data/mongo 创建配置文件 # vi /data/mongo/mongodb.cnf dbpath=/data/mongo/ l ...