- #include <bits/stdc++.h>
- using namespace std;
- #define N 100005
- #define MOD 1000000007
- int a[N], b[N];
- int tree[N];
- int query(int idx){
- long long sum=0;
- while(idx>0){
- sum+=tree[idx];
- sum%=MOD;
- idx -= idx & (-idx);
- }
- return (int) sum%MOD;
- }
- void update(int idx, int x, int n) //n is the size of the array, x is the number to add
- {
- while(idx<=n){
- tree[idx]+=x;
- tree[idx]%=MOD;
- idx += idx & (-idx);
- }
- }
- int main(){
- int ts;
- scanf("%d", &ts);
- for(int p = 1; p <= ts; p++){
- memset(tree, 0, sizeof(tree));
- int n;
- scanf("%d", &n);
- for(int i = 0; i <n; i++){
- scanf("%d", &a[i]);
- b[i] = a[i];
- }
- map<int, int>mp;
- sort(b, b+n);
- int cnt = 2;
- mp[b[0]] = 1;
- for(int i = 1; i <n; i++){
- if(b[i] != b[i-1]){
- mp[b[i]] = cnt;
- cnt++;
- }
- }
- for(int i = 0; i <n; i++){
- update(mp[a[i]], (query(mp[a[i]]-1)+1)%MOD,n);
- }
- printf("Case %d: %d\n",p,query(n)%MOD);
- }
- return 0;
- }
Wednesday, 26 July 2017
Lightoj 1085 All Possible Increasing Subsequences
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment