-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path1085-All-Possible-Increasing-Subsequences.cpp
More file actions
87 lines (60 loc) · 1.09 KB
/
Copy path1085-All-Possible-Increasing-Subsequences.cpp
File metadata and controls
87 lines (60 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#define Last(i) ( (i) & (-i) )
#define MOD 1000000007
using namespace std;
int tree[100050];
int a[100050];
int n;
int cnt;
int update(int i, int val)
{
while(i <= cnt) {
tree[i] = (tree[i] + val) % MOD;
i += Last(i); }
}
int query(int i)
{
int result;
result = 0;
while(i > 0) {
result = (result + tree[i]) % MOD;
i -= Last(i); }
return result;
}
int main()
{
int t;
int result;
int ans;
scanf("%d", &t);
for (int cs = 1; cs <= t; cs++) {
scanf("%d", &n);
cnt = 0;
ans = 0;
memset(a, 0, sizeof a);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
vector <int> b(a, a+n);
memset(tree, 0, sizeof tree);
map <int, int> m;
sort(b.begin(), b.end());
for (int i = 0; i < n; i++) {
if(m.count(b[i]) == 0) {
m[b[i]] = ++cnt;
}
}
for (int i = 0; i < n; i++) {
result = query(m[a[i]] - 1) + 1;
ans = (result + ans) % MOD;
update(m[a[i]], result);
}
printf("Case %d: %d\n", cs, ans);
}
return 0;
}