预处理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. [FJOI 2016] 神秘数

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4408 [算法] 首先考虑一组询问怎样做 : 将数组按升序排序 , 假设我们现在可以表 ...

  2. codevs 1143 纪念品分组

    1143 纪念品分组 2007年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解       题目描述 Description ...

  3. hihoCoder2月29日(字符串模拟)

    时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年: ...

  4. css3 position:sticky

    最近在写一个小程序,项目中遇到一个需求:页面滚动到tab切换菜单时,菜单fixed到页面顶部: 实现方法: 使用小程序的onPageScroll事件,滚动到指定位置添加fixed样式: bug1:获取 ...

  5. ceph学习之PG

    PG的计算公式: 整个集群PG的计算公式 Total PGs = ((Total_number_of_OSD * ) / max_replication_count) 每个POOL中PG的计算公式: ...

  6. sybase SQL记录

    在一个表中复制一行,主键是MLID ';

  7. JS自动让手机调出软键盘,进行输入

    $('.search').click(function(){ $('input[type=text]').focus(); //让input框自动聚焦就可以让手机自动调出软键盘 });

  8. Cube 数据 与 DW 数据对应不上

    场景: 时间维度表:字段(日期) 收费事实表:字段(金额,收费日期,就诊编号) 管理:使用维度表的 日期字段与事实表的 收费日期字段 进行关联,建立多维度数据集. 问题:     DW :   9月份 ...

  9. hue集成各种组件

    一.Hue安装 可以编译安装,我这里有已经编译好的,直接解压使用: hue默认端口:8888 http://gethue.com/ https://github.com/cloudera/hue ht ...

  10. Mac中自定义文件夹中文名

    在OSX系统中,我们打开finer,就会看到很多中文名的文件夹,比如“应用程序”.“桌面”等等,而在系统中都是以英文命名的.我们也可以自己去设置中文名. 首先需要找到设置中文的字符串资源文件,路径是/ ...