题目链接:

  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. iOS面试常见题

    1.耶稣有13个门徒,当中有一个就是出卖耶稣的叛徒,请用排除法找出这位叛徒:13个人围坐一圈,从第一个人開始循环报数,数到三排除,最后剩下的人就是叛徒 int people[13] = {1,2,3, ...

  2. 三分钟教你学Git(十四) 之 线下传输仓库

    有时候还有一个人不能从远程直接clone仓库或者说由于非常大,clone非常慢或其他原因.我们能够使用bundle命令将Git仓库打包,然后通过U盘或者是其他介质拷贝给他,这样他拿到打包好的仓库后能够 ...

  3. 【bzoj1433】[ZJOI2009]假期的宿舍

    按要求连边,跑匈牙利 #include<algorithm> #include<iostream> #include<cstdlib> #include<cs ...

  4. Space for commit to queue couldn't be acquired

    18/07/27 16:53:53 ERROR source.ExecSource: Failed while running command: tail -F /home/MyBgJavaLan/p ...

  5. java 获取路径

    1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user ...

  6. 概率dp集合

    bzoj1076 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝物以后 ...

  7. 解决virtualbox安装增强工具失败的问题

    virtualbox有个增强工具,安装之后用户体验是非常爽的.但是有些时候在安装增强工具会遇到一些小问题,无非是没有安装gcc,make之类的编译工具或是需要安装kernel*.而我遇到的问题在做了这 ...

  8. YTU 2442: C++习题 矩阵求和--重载运算符

    2442: C++习题 矩阵求和--重载运算符 时间限制: 1 Sec  内存限制: 128 MB 提交: 1457  解决: 565 题目描述 有两个矩阵a和b,均为2行3列.求两个矩阵之和.重载运 ...

  9. JS基础篇--JS的event.srcElement与event.target(触发事件对象)

    IE下,event对象有srcElement属性,但是没有target属性; Firefox下,event对象有target属性,但是没有srcElement属性.但他们的作用是相当的,即: fire ...

  10. CollapsingToolbarLayout 收缩显示tilte

    final CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id. ...