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] 的对数 会 ...
随机推荐
- pychon - selenium2Libray源码简介
I. Introduction Selenium2Library是robot framework中主流的测试网页功能的库, 它的本质是对webdriver的二次封装, 以适应robot框架. 百度上一 ...
- 对“针对接口编程,而不是针对实现编程”的理解
今天在阅读<Head First设计模式>的时候,看到了这句话:"针对接口编程,而不是针对实现编程",第一次见到的时候,不太清楚作者想表达的意思,想着到后来看看实例就懂 ...
- this的相关知识
一如既往,直接上代码: function fn(name,age){ var obj=new Object(); obj.name=name; obj.age=age; obj.talk=functi ...
- fzu Problem 2128 最长子串(KMP + strstr 经典好题)
Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长. Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...
- MySQL5.5.28启动错误 The server quit without updating PID file
今天重新安装了一次 MySQL5.5.28 ,但启动的时候老是报错 Starting MySQL.. ERROR! The server quit without updating PID file ...
- Linux下查看access访问日志IP统计命令
查看 access.Log 文件ip统计 cat access.log |awk '{print $1}'|uniq -c |sort -k1,1nr 去掉r则从高到低 cat access.log ...
- hdu 3666 THE MATRIX PROBLEM
差分约束系统. 根据题意,可以写出不等式 L <= (Xij * Ai) / Bj <= U 即 Ai/Bj<=U/Xij和Ai/Bj>=L/Xij 由于差分约束系统是减法.. ...
- 转:Cocoa、Foundation、UIKit、Objective-c、XCode、Interface Builder的概念
Cocoa 是在Mac OS X系统上原生的一个编译环境.他包含两个框架,其实就是一系列的类库,Foundation和AppKit. 在你的iPhone等掌上设备上,使用的则是他的一个子类 - Coc ...
- 第八十四节,css布局小技巧及font-awesome图标使用
css布局小技巧及font-awesome图标使用 图片鼠标放上去遮罩效果,显示文字 当鼠标放上去时 /*最外层div*/ .a{ width: 384px; height: 240px; backg ...
- iOS开发app自动更新的实现
#define kStoreAppId @“xxxxxxxxx” // (appid数字串) -(void)checkAppUpdate { NSDictionary *infoDict = [[NS ...