Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #pragma GCC optimize("conserve-stack")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("-O3")
- #define all(x) x.begin(),x.end()
- #define rall(x) x.rbegin(),x.rend()
- #define ll long long
- #define ld long double
- #define pii pair<int,int>
- #define fi first
- #define se second
- #define isz(x) int(x.size())
- #define ull unsigned long long
- #define vld vector<ld>
- #define vull vector<ull>
- #define vvull vector<vull>
- #define vb vector<bool>
- #define vvb vector<vb>
- #define vvvb vector<vvb>
- #define vvvvb vector<vvvb>
- #define vvvvvb vector<vvvvb>
- #define vi vector<int>
- #define vll vector<ll>
- #define vch vector<char>
- #define vvch vector<vch>
- #define vvvch vector<vvch>
- #define vvi vector<vector<int>>
- #define vvvi vector<vvi>
- #define vvvvi vector<vvvi>
- #define vvvvvi vector<vvvvi>
- #define vvll vector<vector<ll>>
- #define vvvll vector<vvll>
- #define vvvvll vector<vvvll>
- #define vvvvvll vector<vvvvll>
- #define vpii vector<pair<int,int>>
- #define vvpii vector<vpii>
- #define vvvpii vector<vvpii>
- #define vvvvpii vector<vvvpii>
- #define forn(i,n) for(int i=0;i<(int)n;++i)
- #define pb push_back
- using namespace std;
- const double EPS = 1e-9;
- const int UNDEF = -1;
- const int MOD = 1e9 + 7;
- const int INF = 1e9;
- vpii tree;
- const pii E = {-2 * INF, -2 * INF};
- pii get(int x, int lx, int rx, int l, int r){
- if(l <= lx && rx <= r){
- return tree[x];
- }
- if(r <= lx || rx <= l){
- return E;
- }
- int mid = (lx + rx) / 2;
- pii left = get(2 * x + 1, lx, mid, l, r);
- pii right = get(2 * x + 2, mid, rx, l, r);
- if(left.fi < right.fi){
- return right;
- } else if(left.fi > right.fi){
- return left;
- } else {
- return {left.fi, (0LL + left.se + right.se) % MOD};
- }
- }
- void update(int x, int lx, int rx, int i, pii v){
- if(lx + 1 == rx){
- if(tree[x].fi == v.fi){
- tree[x] = {v.fi, (0LL + tree[x].se + v.se) % MOD};
- } else{
- tree[x] = v;
- }
- return;
- }
- int mid = (lx + rx) / 2;
- if(i < mid){
- update(2 * x + 1, lx, mid, i, v);
- } else {
- update(2 * x + 2, mid, rx, i, v);
- }
- pii left = tree[2 * x + 1];
- pii right = tree[2 * x + 2];
- if(left.fi < right.fi){
- tree[x] = right;
- } else if(left.fi > right.fi){
- tree[x] = left;
- } else {
- tree[x] = {left.fi, (0LL + left.se + right.se) % MOD};
- }
- }
- void solve(){
- int n; cin >> n;
- vi a(n);
- forn(i,n) cin >> a[i];
- vi b(a);
- sort(all(b));
- b.erase(unique(all(b)), b.end());
- tree.assign(4 * isz(b), E);
- forn(i,n){
- int j = lower_bound(all(b), a[i]) - b.begin();
- pii x = get(0, 0, isz(b), 0, j);
- if(x == E){
- x = {0, 1};
- }
- update(0, 0, isz(b), j, {x.fi + 1, x.se});
- }
- cout << get(0, 0, isz(b), 0, isz(b)).se;
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int t = 1;
- //cin >> t;
- while (t--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement