hdu_2227_Find the nondecreasing subsequences_树状数组,离散化
题目连接: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_树状数组,离散化的更多相关文章
- hdu4605 树状数组+离散化+dfs
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- BZOJ_5055_膜法师_树状数组+离散化
BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...
- POJ 2299 【树状数组 离散化】
题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...
- HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences ...
- BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...
- POJ 2299 树状数组+离散化求逆序对
给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...
- [HDOJ4325]Flowers(树状数组 离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 关于离散化的简介:http://blog.csdn.net/gokou_ruri/article ...
- Bzoj 1901: Zju2112 Dynamic Rankings 主席树,可持久,树状数组,离散化
1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6321 Solved: 2628[Su ...
- CF 61E 树状数组+离散化 求逆序数加强版 三个数逆序
http://codeforces.com/problemset/problem/61/E 题意是求 i<j<k && a[i]>a[j]>a[k] 的对数 会 ...
随机推荐
- 【cocos2d-js 3.0】制作2048
2048:在一个4X4的方阵中,玩家需要滑动上面的数字,如果俩个数字相邻并且相等,则相加,需要达到2048,方可胜利. 因为在浏览器操作,所以此例的操作方法为:键盘上的w,s,a,d代表上下左右,也可 ...
- AMD规范
common.js主要语法就是 var math=require('math'); math.add(2,3); require()用于加载模块就行了. 二行math.add(2, 3),在第一行re ...
- C#委托与事件讲解(一)
首先,我们还是先说说委托吧,从字面上理解,只要是中国人应该都知道这个意思,除非委托2个中文字不认识,举个例子,小明委托小张去买车票. 但是在我们的程序世界里,也是这么的简单吗?当然,什么是OO ...
- datables的基本操作
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- android 图片加载优化,避免oom问题产生
1,及时回收bitmap,在activity的onstop()和onDestory()里面调用如下代码进行bitmap的回收: // 先判断是否已经回收 if(bitmap != null & ...
- CentOS6.3配置SVN之subversion1.7.7
今天配置了 SVN 记在这儿 备忘: 1. 下载 svn 软件包和依赖包 cd /mydata/soft wget http://labs.mop.com/apache-mirror/subversi ...
- Snacks
Snacks 题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5692 dfs序+线段树 这道题涉及到对整棵树的值修改,考虑将树状结构用dfs ...
- html .css 实现图片滑动和自动播放特效移动端 HTML 5中添加了以touch 开头的事件
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta ...
- JS复习:二十一章
一.XHR对象 Ajax( )对象的核心技术就是XMLHttpRequest对象. 二.XHR的用法 在使用XHR对象时,要调用的第一个方法是open( ),它接受3个参数:要发送的请求类型(&quo ...
- POJ 2209 The King#贪心
(- ̄▽ ̄)-* 水 //水题:潜力^e为正数(e为2时都可以)的儿子都可以去上战场了, //英文要看懂,exponent指数,不超过3的正数 #include<iostream> #i ...