forked from mrsac7/CSES-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
1748 - Increasing Subsequence II.cpp
51 lines (48 loc) · 1.03 KB
/
1748 - Increasing Subsequence II.cpp
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
/*
Problem Name: Increasing Subsequence II
Problem Link: https://cses.fi/problemset/task/1748
Author: Sachin Srivastava (mrsac7)
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
map<int,int> mp;
const int mxN = 200005;
const int md = 1e9+7;
int bit[mxN];
void upd(int k, int v) {
for (; k < mxN; k += k&-k)
(bit[k] += v)%=md;;
}
int qry(int k) {
int sum = 0;
for (; k > 0; k -= k&-k)
(sum += bit[k])%=md;
return sum;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r" , stdin);
freopen("output.txt", "w", stdout);
#endif
int n; cin>>n;
//index compression
int a[n];
set<int> s;
for (int i = 0; i < n; i++) {
cin>>a[i];
s.insert(a[i]);
}
int ct = 0;
for (auto i: s)
mp[i] = ++ct;
int ans = 0;
for (int i = 0; i < n; i++) {
int x = qry(mp[a[i]]-1)+1;
(ans += x)%=md;
upd(mp[a[i]], x);
}
cout<<ans;
}