题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2227

题意:给你一个集合,让你求递增子序列有多少个,和树状数组求逆序对差不多,不过数据比较大,要离散化一下。

 #include<cstdio>
#include<algorithm>
#define FFC(i,a,b) for(int i=a;i<=b;i++)
#define LL long long
using namespace std;
LL tree[];
int maxn,mod=,l,r,t,len,mid;
int dt[],a[];
void init(int n){maxn=n;for(int i=;i<=maxn;i++)tree[i]=;}
inline void add(int x,int v){for(int i=x;i<=maxn;i+=i&-i)tree[i]=(tree[i]+v)%mod;}
inline LL sum(int x){LL an=;for(;x>;x-=x&-x)an=(an+tree[x])%mod;return an;}
inline int lowb(int x){for(l=,r=len;l<=r;)if(a[mid=(l+r)>>]>=x)r=(t=mid)-;else l=mid+;}
int main(){
int n;
while(~scanf("%d",&n)){
FFC(i,,n){
scanf("%d",&dt[i]);
a[i]=dt[i];//离散化数组
}
sort(a+,a++n);
len=unique(a+,a++n)-a-;//离散化
init(len);
LL ans=;
FFC(i,,n){
lowb(dt[i]);//二分查找
int tt=sum(t);
add(t,tt+);
ans=(ans+tt+)%mod;//注意,一个数它本身也是一个递增子列,所以要加一
}
printf("%lld\n",ans);
}
return ;
}

hdu_2227_Find the nondecreasing subsequences_树状数组,离散化的更多相关文章

  1. hdu4605 树状数组+离散化+dfs

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. BZOJ_5055_膜法师_树状数组+离散化

    BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...

  3. POJ 2299 【树状数组 离散化】

    题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...

  4. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  5. BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学

    1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...

  6. POJ 2299 树状数组+离散化求逆序对

    给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...

  7. [HDOJ4325]Flowers(树状数组 离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 关于离散化的简介:http://blog.csdn.net/gokou_ruri/article ...

  8. Bzoj 1901: Zju2112 Dynamic Rankings 主席树,可持久,树状数组,离散化

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6321  Solved: 2628[Su ...

  9. CF 61E 树状数组+离散化 求逆序数加强版 三个数逆序

    http://codeforces.com/problemset/problem/61/E 题意是求 i<j<k && a[i]>a[j]>a[k] 的对数 会 ...

随机推荐

  1. 利用poi向excle写入数据

    import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import org ...

  2. SpringMVC初步——HelloWorld的实现

    开通博客园好几个月了,今天开始要用博客园记录自己的学习过程! 目录: 导包: 1. 配置web.xml文件的springDispatcherServlet 在xml中 alt+/ 找到springdi ...

  3. intellij idea 12 搭建maven web项目

    原来公司一直使用eclipse,突然使用这个intellij还真有点不习惯,等用了一段时间才发现的确好用,因为也是刚开始用,所以很多不理解的地方,搭建一个项目从头好好了解下intellij 最开始的m ...

  4. Link方式导入java项目

    一.环境说明 我用的是eclipse3.3.2,并安装了myeclipse的插件. 二.工程文件说明 一共三个文件夹: javacode:存放Java源文件,包含多个子文件夹,每个子文件夹表示一个单独 ...

  5. iOS开发app自动更新的实现

    #define kStoreAppId @“xxxxxxxxx” // (appid数字串) -(void)checkAppUpdate { NSDictionary *infoDict = [[NS ...

  6. AuthenticationManager, ProviderManager 和 AuthenticationProvider

    AuthenticationManager是一个接口: public interface AuthenticationManager { Authentication authenticate(Aut ...

  7. jQuery复习:第五章

    一.表单应用 1.表单验证: 首先创建一个表单: <form method="post" action=""> <div class=&quo ...

  8. 城市字符串----转数组( 加空格---preg_split) 正则分割字符串 --> 成数组

    正则 以 斜杠开始 斜杠 结束   斜杠 包围起来  /  / 字母 反斜杠 转义  \s    space 匹配空格 多个空格 [ \s  ]+   中括号 包围起来 public function ...

  9. 线索thread二叉树

    对于一个普通的二叉树 我们可以很明显的看到,在一个二叉树中,会有许多的空结点,而这些空结点必然会造成空间的浪费,为了解决这个问题,我们可以引入线索二叉树,把这些空结点利用起来,利用 '^' 记录给定结 ...

  10. ARC 下面可能导致的内存问题

    一.ARC相对MRC来说,减轻了程序员的大部分内存管理工作,使用ARC的时候也需要十分清除内存管理的原理,不然可能带来一些很难调试的问题.下面是ARC下面需要注意的一些问题 1)对象互相引用,形成引用 ...