1085 - All Possible Increasing Subsequences[树状数组]
来源:互联网 发布:日本经济数据2016 编辑:程序博客网 时间:2024/06/06 00:36
An increasing subsequence from a sequence A1, A2 ... An is defined by Ai1, Ai2 ... Aik, where the following properties hold
1. i1 < i2 < i3 < ... < ik and
2. Ai1 < Ai2 < Ai3 < ... < Aik
Now you are given a sequence, you have to find the number of all possible increasing subsequences.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 105) denoting the number of elements in the initial sequence. The next line will contain n integers separated by spaces, denoting the elements of the sequence. Each of these integers will be fit into a 32 bit signed integer.
Output
For each case of input, print the case number and the number of possible increasing subsequences modulo 1000000007.
Sample Input
Output for Sample Input
3
3
1 1 2
5
1 2 1000 1000 1001
3
1 10 11
Case 1: 5
Case 2: 23
Case 3: 7
Notes
1. For the first case, the increasing subsequences are (1), (1, 2), (1), (1, 2), 2.
2. Dataset is huge, use faster I/O methods.
#include <bits/stdc++.h>using namespace std;const int MAX_N = 1e5+100;const int MOD = 1000000007;int bit[MAX_N],n,T,a[MAX_N],b[MAX_N];void add(int i,int x){ while(i<=n){ bit[i] += x; while(bit[i]>MOD) bit[i] -= MOD; i+=i&-i; }}int sum(int i){ int res = 0; while(i>0){ res += bit[i]; i -= i&-i; while(res>MOD) res -= MOD; } return res;}int main(){ scanf("%d",&T); for(int t=1;t<=T;t++){ memset(bit,0,sizeof(bit)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&a[i]); b[i] = a[i]; } // 以下代码为离散化操作 sort(a,a+n); int N = unique(a,a+n)-a; for(int i=0;i<n;i++){ b[i] = lower_bound(a,a+N,b[i])-a; b[i]+=1; } // 树状数组维护值 for(int i=0;i<n;i++){ int s = sum(b[i]-1); s++; add(b[i],s); } int ans = sum(n); printf("Case %d: %d\n",t,ans); } return 0;}
- 1085 - All Possible Increasing Subsequences[树状数组]
- [树状数组]LightOJ 1085 - All Possible Increasing Subsequences
- Lightoj 1085 All Possible Increasing Subsequences (树状数组+DP)
- lightoj 1085 - All Possible Increasing Subsequences 【树状数组优化dp】
- lightoj1085 - All Possible Increasing Subsequences(树状数组)
- LightOJ 1085 All Possible Increasing Subsequences (DP&离散化&树状数组)
- lightoj 1085 All Possible Increasing Subsequences(递推式+离散化+树状数组维护)
- lightoj 1085 All Possible Increasing Subsequences
- Light OJ 1085 - All Possible Increasing Subsequences
- lightoj1085 All Possible Increasing Subsequences
- LightOJ 1085 - All Possible Increasing Subsequences(DP + 线段树 + 离散)
- light oj1085All Possible Increasing Subsequences(树状数组+离散化+递推)
- Increasing Subsequences
- Increasing Subsequences
- 树状数组 hdu2227 Find the nondecreasing subsequences
- Codeforces 597C Subsequences dp + 树状数组
- 597C. Subsequences【DP】【树状数组】
- [dp+树状数组优化] CF597C. Subsequences
- Linux 中页的回收
- 10个强大的Apache开源模块
- uva 1399 - Puzzle(AC自动机)
- TCP/IP详解--三次握手和四次握手 Dos攻击
- java中static作用详解
- 1085 - All Possible Increasing Subsequences[树状数组]
- 第十一章 11.3.4节练习
- 基础图形管线
- ThreadLocal保证DateFormat线程安全
- Java现场信息获取蛋疼方法
- 天猫大数据总结2
- 开篇:AutoCAD ObjectARX 之三金开发 -- 介绍
- SQL的关联查询
- C/C++中各种类型int、long、double、char表示范围(最大最小值)