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] 的对数 会 ...
随机推荐
- 如何判断Socket已经关闭
引子 前段时间我们的服务由于一台交换机网络出现故障,导致数据库连接不上,但是在数据库的连接超时参数设置不合理,connect timeout设置的过长,导致接口耗时增加.DB连接超时后线程未正常结束, ...
- C++虚函数继承的bug
闲来无事想测试一下:如果在派生类中重写基类的虚函数,那么允不允许改变虚函数的访问权限,结果颠覆了三观..... 基类Base,拥有public方法test(),test()为虚函数 派生类Derive ...
- 解决 GoogleApi 无法访问的问题
因为 google 被天朝屏蔽,所以很多运用了 fonts.googleapis 的网站都打开很慢,会直到加载 fonts.googleapis 超时才能打开网页. 在本地开发时,可以引用国内的CDN ...
- 正向代理vs.反向代理
正向代理 也就是传说中的代理,他的工作原理就像一个跳板,简单的说,我是一个用户,我访问不了某网站,但是我能访问一个代理服务器这个代理服务器呢,他能访问那个我不能访问的网站于是我先连上代 ...
- tomcat bio nio apr 模式性能测试
转自:tomcat bio nio apr 模式性能测试与个人看法 11.11活动当天,服务器负载过大,导致部分页面出现了不可访问的状态.那后来主管就要求调优了,下面是tomcat bio.nio.a ...
- jQuery动态添加元素事件
在项目中遇到需要jQuery动态添加元素的事件,做了一个demo,方便以后遇到相同的问题可以用上: <!DOCTYPE html> <html> <head> &l ...
- C#指定某用户对某文夹件的访问权限
using System.Security.AccessControl; //设置myFloder文件夹的iis访问权限 string userAccount = @&q ...
- webpack 相关资料
github webpack Youtube: Advanced Webpack code splitting list of plugins webpack examples What's new ...
- 浅析const标识符在C++函数的功能
范例: class matrix { public: matrix(){}; const double getvalue(const unsigned row, const unsigned colu ...
- OSG+Python
测试平台(1)Fedora19 x86 [cc@localhost ~]$ lspci | grep VGA :) :00.0 VGA compatible controller: NVIDIA Co ...