题目链接:

  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. 基于PHP函数的alert弹框

    可以设置弹出信息,跳转地址,跳转的时间,跳转的信息标题提示: 手机端加上<meta name='viewport' content='width=device-width, initial-sc ...

  2. 距特征之k阶距概念

    k阶原点距和k阶中心距各是说明什么数字特征 http://www.cnblogs.com/emanlee/archive/2011/04/25/2028628.html 二阶中心距,也叫作方差,它告诉 ...

  3. mvn_action

    validate(验证): 验证项目正确,并且所有必要信息可用. compile(编译): 编译项目源码 test(测试): 使用合适的单元测试框架测试编译后的源码. package(打包): 源码编 ...

  4. 有关 安装MySQL的错误

    1.登录SQLyog 密码与MySQL设置不一致. 2.上一次安装MySQL没有卸载干净,(排查删除: (1)搜索C盘删除相关文件(隐藏目录   C:\ProgramData  下寻找 mysql ) ...

  5. redis13-----配置文件

    ==配置文件全解=== ==基本配置 daemonize no 是否以后台进程启动 databases 创建database的数量(默认选中的是database ) #刷新快照到硬盘中,必须满足两者要 ...

  6. vue 数组和对象渲染问题

    vue 数组和对象渲染问题 最近项目有点忙碌,遇到好多问题都没有总结(╥﹏╥),在开发过程中,取vuex中的数组渲染完成之后,再次修改数组的值,数据更新了,但是视图并没有更新.以为是数组更新的问题,后 ...

  7. Vue实现仿淘宝商品详情属性选择的功能

    Vue实现仿淘宝商品详情属性选择的功能 先看下效果图:(同个属性内部单选,属性与属性之间可以多选) 主要实现过程: 所使用到的数据类型是(一个大数组里面嵌套了另一个数组)具体格式如下:   attrA ...

  8. codeforces 454B. Little Pony and Sort by Shift 解题报告

    题目链接:http://codeforces.com/problemset/problem/454/B 题目意思:给出一个序列你 a1, a2, ..., an. 问每次操作只能通过将最后一个数拿出来 ...

  9. 一步一步学Silverlight 2系列(21):如何在Silverlight中调用JavaScript

    概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...

  10. c语言中为什么左移不分符号数无符号数,而右移分呢??

    因为在C语言标准中,只规定了无符号数的移位操作是采用逻辑移位(即左移.右移都是使用的逻辑左移和逻辑右移).而对于有符号数,其左移操作还是逻辑左移,但右移操作是采用逻辑右移还是算术右移就取决于机器了!( ...