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 ...
随机推荐
- (转)apktool+dex2jar+jd_gui
转:http://www.cnblogs.com/MichaelGuan/archive/2011/10/25/2224578.html apktool: 可以解析资源文件,比如布局文件xml等,方便 ...
- [git]基本用法1
一.实验说明 本节实验为 Git 入门第一个实验,可以帮助大家熟悉如何创建和使用 git 仓库. 二.git的初始化 在使用git进行代码管理之前,我们首先要对git进行初始化. 1.Git 配置 使 ...
- .getClass()和.class的区别
一直在想.class和.getClass()的区别,思索良久,有点思绪,然后有网上搜了搜,找到了如下的一篇文章,与大家分享. 原来为就是涉及到java的反射----- Java反射学习 所谓反射,可以 ...
- lintcode-170-旋转链表
170-旋转链表 给定一个链表,旋转链表,使得每个节点向右移动k个位置,其中k是一个非负数 样例 给出链表1->2->3->4->5->null和k=2 返回4-> ...
- windows批处理学习(call与start)---02
参考:https://www.cnblogs.com/Braveliu/p/5078283.html 一.call命令总结 (1)call命令简介 语法: call [ [Drive:] [Path] ...
- GetTickCount 和getTickCount
GetTickCount:正常读取时间函数 getTickCount:不知道是什么鬼东东函数 都包含在windows.h中..运行出的结果天壤之别~~~
- Spring AOP 源码解析
什么是AOP AOP(Aspect-OrientedProgramming,面向方面编程),可以说是OOP(Object-Oriented Programing,面向对象编程)的补充和完善.OOP引入 ...
- SpringBoot JDBC/AOP
JDBC 工程结构: pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmln ...
- bsxfun函数
函数功能:两个数组间元素逐个计算的二值操作 使用方法:C=bsxfun(fun,A,B) 两个数组A合B间元素逐个计算的二值操作,fun是函数句柄或者m文件,也可以为如下内置函数: @plus 加@m ...
- 【刷题】BZOJ 4259 残缺的字符串
Description 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时,这两个串已经老化了,每个串都有不同 ...