机房的人问我树状数组怎么做这题......

树状数组维护$len, num$表示$LIS$的长度和数量即可

复杂度$O(n \log n)$

注:$O(n \log n)$二分+单调栈才是真神仙

具体看代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; extern inline char gc() {
static char RR[], *S = RR + , *T = RR + ;
if(S == T) fread(RR, , , stdin), S = RR;
return *S ++;
}
inline int read() {
int p = , w = ; char c = gc();
while(c > '' || c < '') { if(c == '-') w = -; c = gc(); }
while(c >= '' && c <= '') p = p * + c - '', c = gc();
return p * w;
} #define mod 1000000007
#define ri register int
#define sid 50050 int n, cnp, H[sid], a[sid];
struct aha {
int len, num;
} t[sid], f[sid]; void upd(aha &x, aha y) {
if(x.len > y.len) return;
if(x.len < y.len) x = y;
else x.num += y.num, x.num %= mod;
} aha qry(int x) {
aha ret = { , };
for(ri i = x; i; i -= i &(-i)) upd(ret, t[i]);
return ret;
} aha add(int x, aha v) {
for(ri i = x; i <= cnp; i += i & (-i)) upd(t[i], v);
} int main() {
n = read();
for(ri i = ; i <= n; i ++) a[i] = H[i] = read();
sort(H + , H + n + );
cnp = unique(H + , H + n + ) - H - ;
for(ri i = ; i <= n; i ++) a[i] = lower_bound(H + , H + cnp + , a[i]) - H;
for(ri i = ; i <= n; i ++) {
f[i] = qry(a[i] - ); f[i].len ++;
add(a[i], f[i]);
}
aha ans = { , };
for(ri i = ; i <= n; i ++) upd(ans, f[i]);
printf("%d\n", ans.num);
return ;
}

51nod1376 最长上升子序列的数量的更多相关文章

  1. 51nod1376 最长递增子序列的数量

    O(n2)显然超时.网上找的题解都是用奇怪的姿势写看不懂TAT.然后自己YY.要求a[i]之前最大的是多少且最大的有多少个.那么线段树维护两个值,一个是当前区间的最大值一个是当前区间最大值的数量那么我 ...

  2. 【51nod】1376 最长递增子序列的数量

    数组A包含N个整数(可能包含相同的值).设S为A的子序列且S中的元素是递增的,则S为A的递增子序列.如果S的长度是所有递增子序列中最长的,则称S为A的最长递增子序列(LIS).A的LIS可能有很多个. ...

  3. 51NOD 1376 最长递增子序列的数量 [CDQ分治]

    1376 最长递增子序列的数量 首先可以用线段树优化$DP$做,转移时取$0...a[i]$的最大$f$值 但我要练习$CDQ$ $LIS$是二维偏序问题,偏序关系是$i<j,\ a_i< ...

  4. 51nod 1376 最长递增子序列的数量(线段树)

    51nod 1376 最长递增子序列的数量 数组A包含N个整数(可能包含相同的值).设S为A的子序列且S中的元素是递增的,则S为A的递增子序列.如果S的长度是所有递增子序列中最长的,则称S为A的最长递 ...

  5. 51nod 1376 最长上升子序列的数量 | DP | vector怒刷存在感!

    51nod 1376 最长上升子序列的数量 题解 我们设lis[i]为以位置i结尾的最长上升子序列长度,dp[i]为以位置i结尾的最长上升子序列数量. 显然,dp[i]要从前面的一些位置(设为位置j) ...

  6. 51Nod 1376 最长递增子序列的数量 —— LIS、线段树

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1376 1376 最长递增子序列的数量 基准时间限制:1 秒 空 ...

  7. 51Nod 1376 最长递增子序列的数量 (DP+BIT)

    题意:略. 析:dp[i] 表示以第 i 个数结尾的LIS的长度和数量,状态方程很好转移,先说长度 dp[i] = max { dp[j] + 1 | a[i] > a[j] && ...

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

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

  9. 51nod 1376 最长递增子序列的数量(不是dp哦,线段树 +  思维)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1376 题解:显然这题暴力的方法很容易想到就是以每个数为结尾最 ...

随机推荐

  1. rxjs自定义operator

    rxjs自定义operator

  2. Sqlmap与burpsuite动态更新某些参数

    有如下注入点: http://localhost/id=1&order_nu=1 情况说明: id为注入点,  每一次注入时, order_nu不能跟上次的一样(假说这个order_nu为一个 ...

  3. flask基础之jijia2模板使用基础(二)

    前言 在以前前后端不分离的时代,后台程序员往往又当爹又当妈,需要将前端程序员写的h5页面填充模板语言.而jijia2是一门十分强大的python的模板语言,是flask框架的核心模块之一.先简单介绍一 ...

  4. django框架<三>

    一.ORM操作  1.django orm创建数据库的方法 (1)指定连接pymysql(python3.x),先配置__init__.py import pymysql pymysql.instal ...

  5. 在新版linux上编译老版本的kernel出现kernel/timeconst.h] Error 255

    在使用ubuntu16.4编译Linux-2.6.31内核时出现这样的错误 可以修改timeconst.pl的内容后正常编译. 以下是编译错误提示的内容: Can't use 'defined(@ar ...

  6. HTML标签学习之路-001

    1.html的注释 <!--这里是注释内容--> <!--代表注释内容的开始 -->代表注释内容结束 注释部分,不会被浏览器输出,只是作为代码的说明,供开发者查阅 2.HTML ...

  7. Linux文档时间戳查看和修改——stat

    查看文件时间戳命令:stat awk.txtFile: `awk.txt'Size: 20  Blocks: 8  IO Block: 4096  regular fileDevice: 801h/2 ...

  8. python开发学习-day03(set集合、collection系列 、深浅拷贝、函数)

    s12-20160116-day03 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  9. 一个配置文件收集多个日志-if根据type类型判断

    1.同时收集/var/log/messages日志和secure日志 #vim /etc/logstash/conf.d/system.conf input { file { path => & ...

  10. LoadRunner:VuGen开发脚本步骤(一)

    一.测试过程 1.规划测试:分析应用程序.定义测试目标.方案实施. 2.创建Vuser脚本. 3.创建方案:方案包括运行 Vuser 的计算机的列表.运行 Vuser 脚本的列表以及在方案执行期间运行 ...