LightOJ 1085 - All Possible Increasing Subsequences 树状数组+离散
http://www.lightoj.com/volume_showproblem.php?problem=1085
题意:求一个序列的递增子序列个数。
思路:找规律可以发现,某个数作为末尾数的种类数为所有比它小的数的情况+1。使用树状数组查找即可。 C++11 的auto在Lightoj上不能用/.\
/** @Date : 2016-12-01-21.58
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/ #include<bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const int mod = 1000000007; int C[N], a[N]; void add(int p, int v)
{
while(p < N)
{
C[p] += v;
C[p] %= mod;
p += (-p) & p;
}
} int sum(int p)
{
int ans = 0;
while(p)
{
ans += C[p];
ans %= mod;
p -= (-p) & p;
}
return ans;
}
int main()
{
int T;
int cnt = 0;
cin >> T;
while(T--)
{
MMF(C);
int n;
scanf("%d", &n); map<int , int>q; for(int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
q[a[i]] = 1;
} int c = 1;
for(auto i = q.begin(); i != q.end(); i++)
i->se = c++; /*map<int , int>::iterator it;
for( it = q.begin(); it != q.end(); it++)
it->se = c++;*/
for(int i = 1; i <= n; i++)//找规律可以发现,某个数作为末尾数的种类数为所有比它小的数的情况+1
{
int x = q[a[i]];
add(x, sum(x - 1) + 1);
}
printf("Case %d: %d\n", ++cnt, sum(c - 1));
}
return 0;
}
LightOJ 1085 - All Possible Increasing Subsequences 树状数组+离散的更多相关文章
- Codeforces 597C. Subsequences (树状数组+dp)
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...
- [Codeforces261D]Maxim and Increasing Subsequence——树状数组+DP
题目链接: Codeforces261D 题目大意:$k$次询问,每次给出一个长度为$n$的序列$b$及$b$中的最大值$maxb$,构造出序列$a$为$t$个序列$b$连接而成,求$a$的最长上升子 ...
- CF597C Subsequences 树状数组 + 动态规划
设$f(i, j)$表示以$i$结尾的,长为$j$的上升子序列的数量 转移时用树状数组维护即可 复杂度为$O(kn \log n)$ 注:特判0 #include <cstdio> #in ...
- 【BZOJ】1818: [Cqoi2010]内部白点(树状数组+离散+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1818 这一题一开始我就看错了,bzoj的那个绝对值109简直坑人,应该是10^9,我直接写了个暴力. ...
- HDU-4605 Magic Ball Game 树状数组+离散+dfs
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4605 题意:给一颗树,每个节点有个权值w[u],每个节点只有两个儿子或者没有儿子,从根节点放下一个小球 ...
- bzoj 5055: 膜法师 树状数组+离散
先枚举每一个数,看它前面有几个比它小,算一下和为sum1,后面有几个比它大,算一下和为sum2,对答案的贡献为A[i]*sum1*sum2. 离散化后,树状数组就可以了. 就是倒着一边,顺着一边,统计 ...
- Codeforces Testing Round #12 C. Subsequences 树状数组
C. Subsequences For the given sequence with n different elements find the number of increasing s ...
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- hdu_5877_Weak Pair(离散+DFS+树状数组)
题目链接:hdu_5877_Weak Pair 题意: 给你一棵树,让你找有多少对满足那两个条件的weak pair 题解: 有人用Treap,我不会,然后我用树状数组+离散来替代Treap,用DFS ...
随机推荐
- OSI七层协议模型及OSI参考模型中的数据封装过程
转载自:http://blog.csdn.net/qq_14935437/article/details/71081546 OSI模型,即开放式通信系统互联参考模型(Open System Inter ...
- POJ 1639 Picnic Planning(最小度限制生成树)
Description The Contortion Brothers are a famous set of circus clowns, known worldwide for their inc ...
- PHPCMS调取当前栏目的描述、文章位置导航、当前栏目链接、当前栏目名称
当我们填写了栏目描述,怎么调用出来. 使用 {$CATEGORYS[$catid][description]} 就可以把栏目的描述调用出来 下面三个也比较常用{catpos($catid)} 显示文章 ...
- bootstrap使用中遇到的坑
一.例如: <div class="form-group"> <label class="control-label col-lg-3"> ...
- python切片详解
先从原理上分析切片运算: list的切片,内部是调用__getitem__,__setitem__,__delitem__和slice函数.而slice函数又是和range()函数相关的. 给切片传递 ...
- c#笔记整理 关于继承与多态等
[ 塔 · 第 二 条 约 定 ] c#面向对象基础 整理private.protected.public.abstract等的异同 public 公有访问.不受任何限制. private 私有访问. ...
- PHP利用pcntl_exec突破disable_functions
http://fuck.0day5.com/?p=563 PHP突破Disable_functions执行Linux命令 利用dl函数突破disable_functions执行命令 http://ww ...
- 【OpenGL】无法启动此程序,因为计算机中丢失 glut32.dll。尝试重新安装该程序以解决此问题。
运行OpenGL程序的时候报错,如图: 解决方法:把glut32.dll复制到C:\Windows\SysWOW64目录下,而不是像网上教程那样复制到C:\Windows\System32目录下. 原 ...
- 修改QQ各版本的默认保存位置(聊天记录)
这几天没少折腾windows,都有点烦了,我是那种有强迫症的,只要知道的自己没有做到的会感觉到浑身不爽的因为系统重装了好几次,QQ也没少安装几次,我使用的是TM的QQ(没有 那么多烦人的广告,娱乐组件 ...
- VS2012完全卸载
1.先交VS2012的ISO通过Ultraiso载入2.DOS命中输入 I:\vs_ultimate.exe /uninstall /force 或 I:vs_ultimate.exe /uninst ...