题目链接:

  FZu  Problem 2236 第十四个目标

题目描述:

  给出一个n个数的序列,问这个序列内严格递增序列有多少个?不要求连续

解题思路:

  又遇到了用线段树来优化dp的题目,线段树节点里面保存所表达区间里面的方案数。先离散化序列(升序排列),建树,然后按照没有sort前的顺序向线段树里面加点,每次查询小于该数的方案数目+1, 就是当前节点插入进去能影响的方案数目。在线段树对应位置加上新增加的数目即可。

 #include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; #define lson 2*root
#define rson 2*root+1
typedef __int64 LL;
const LL mod = ;
const LL INF= 1e14+;
const int maxn = ; struct node
{
int l, r;
LL num;
int mid ()
{
return (l + r) / ;
}
} tree[maxn*];
LL a[maxn], b[maxn]; void build (int root, int l, int r)
{
tree[root].l = l;
tree[root].r = r;
tree[root].num = ;
if (l == r)
return ; build (lson, l, tree[root].mid());
build (rson, tree[root].mid()+, r);
}
void Insert (int root, LL x, int y)
{
if (tree[root].l == tree[root].r && tree[root].l == y)
{
tree[root].num =(tree[root].num + x) % mod;
return ;
} if (tree[root].mid() >= y)
Insert (lson, x, y);
else
Insert (rson, x, y);
tree[root].num = (tree[lson].num + tree[rson].num) % mod;
}
LL query (int root, int l, int r)
{
if (tree[root].l == l && tree[root].r == r)
return tree[root].num; if (tree[root].mid() >= r)
return query (lson, l, r);
else if (tree[root].mid() < l)
return query (rson, l, r);
else
{
LL num = ;
num += query (lson, l, tree[root].mid());
num += query (rson, tree[root].mid()+, r);
return num % mod;
}
} int main ()
{
int n; while (scanf ("%d", &n) != EOF)
{
for (int i=; i<n; i++)
{
scanf ("%I64d", &a[i]);
b[i] = a[i];
} sort (a, a+n);
int m = unique (a, a+n) - a; LL ans = ;
build (, , m);
for (int i=; i<n; i++)
{
LL nu, tmp = lower_bound (a, a+m, b[i]) - a;
if (tmp == )
nu = ;
else
nu = query (, , tmp-); Insert (, nu+, tmp);
} printf ("%I64d\n", query (, , m));
}
return ;
}
///4 1 2 2 3

FZu Problem 2236 第十四个目标 (线段树 + dp)的更多相关文章

  1. Problem 2236 第十四个目标

    Problem 2236 第十四个目标 Accept: 4    Submit: 6Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem D ...

  2. FZU 2079 最大获利(线段树+DP)

    Description Sean准备投资一些项目.有n个投资项目,投资第i个项目需要花费Ci元.Sean发现如果投资了某些编号连续的项目就能赚得一定的钱.现在给出m组连续的项目和每组能赚得的钱,请问采 ...

  3. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  4. Tsinsen A1219. 采矿(陈许旻) (树链剖分,线段树 + DP)

    [题目链接] http://www.tsinsen.com/A1219 [题意] 给定一棵树,a[u][i]代表u结点分配i人的收益,可以随时改变a[u],查询(u,v)代表在u子树的所有节点,在u- ...

  5. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  6. POJ 3468 A Simple Problem with Integers 【线段树】

    题目链接 http://poj.org/problem?id=3468 思路 线段树 区间更新 模板题 在赋初始值的时候,按点更新区间就可以 AC代码 #include <cstdio> ...

  7. [Codeforces 464E] The Classic Problem(可持久化线段树)

    [Codeforces 464E] The Classic Problem(可持久化线段树) 题面 给出一个带权无向图,每条边的边权是\(2^{x_i}(x_i<10^5)\),求s到t的最短路 ...

  8. [Codeforces Round #296 div2 D] Clique Problem 【线段树+DP】

    题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi ...

  9. [CF 474E] Pillars (线段树+dp)

    题目链接:http://codeforces.com/contest/474/problem/F 意思是给你两个数n和d,下面给你n座山的高度. 一个人任意选择一座山作为起始点,向右跳,但是只能跳到高 ...

随机推荐

  1. Linux input子系统实例分析(二)

    紧接着上一节的实例我们来分析调用的input子系统的接口: 1. input_dev,用来标识输入设备 1: struct input_dev { 2: const char *name; //设备名 ...

  2. php利用cookie防止重复提交解决办法

    原理:如果数据通过了上边的两次验证,说明数据是合法有效的数据,这时候我们把提交的数据串接为一个字符串,并用MD5加密后得到一个MD5的值. 接着我们把这个值通过Cookie放进客户端,当用户下一次提交 ...

  3. UIView局部点击

    今天上班遇到一种情况,需要局部响应点击事件,比如在一个UIImageView中设置一个小圆圈图片,要求点击圆圈里面不响应点击,点击小圆圈外面的部分响应点击.可以通过重写hitTest:withEven ...

  4. java和jar命令

    IDEA打可运行jar http://bglmmz.iteye.com/blog/2058785 -jar参数运行应用时classpath的设置方法 你是否在使用java -jar参数运行打包好的ja ...

  5. 字符串查找函数(BF)

    //模拟字符串定位函数 // s: abcbbghi // t: ghi // 返回6 #include <iostream> #include <string> #inclu ...

  6. 使用TextView实现跑马灯的效果

    1.定义textView标签的4个属性: android:singleLine="true"//使其只能单行 android:ellipsize="marquee&quo ...

  7. SDOI2016 Round1 题解

    BZOJ4513 储能表 数位DP,f[i][2][2][2]表示前i位,是否卡n的上界,是否卡m的上界,是否卡k的下界,枚举每一维的下一位直接转移. #include<cstdio> # ...

  8. Laravel中常见的错误与解决方法小结

    一.报错: 「Can't swap PDO instance while within transaction」 通过查询 Laravel 源代码,可以确认异常是在 setPdo 方法中抛出的: ? ...

  9. Android Studio手动下载配置Gradle的方法

    1 问题 (1) android sutdio第一次打开一个工程巨慢怎么办? (2) 手动配置Gradle Home为什么总是无效? (3) 明明已经下载了Gradle,配置了gradle home, ...

  10. css3 appearance 改变元素外观

    h5 input标签的默认样式去除: 去掉date类型<input>框的叉叉: ::-webkit-clear-button { -webkit-appearance: none; } 去 ...