Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <iomanip>
- #include <queue>
- #include <cmath>
- #include <algorithm>
- #include <tuple>
- #include <iomanip>
- #include <stdio.h>
- #include <numeric>
- #include <map>
- #include <bitset>
- #include <set>
- #include <stack>
- #include <queue>
- #include <unordered_set>
- #include <cassert>
- //#pragma GCC optimize("Ofast,no-stack-protector")
- //#pragma GCC optimize("O3")
- //#pragma GCC target("avx2")
- //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
- //#pragma GCC optimize("unroll-loops")
- //#pragma GCC optimize("fast-math")
- //#pragma GCC optimize("section-anchors")
- //#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
- //#pragma GCC optimize("vpt")
- //#pragma GCC optimize("rename-registers")
- //#pragma GCC optimize("move-loop-invariants")
- //#pragma GCC optimize("unswitch-loops")
- //#pragma GCC optimize("function-sections")
- //#pragma GCC optimize("data-sections")
- //#pragma GCC optimize("branch-target-load-optimize")
- //#pragma GCC optimize("branch-target-load-optimize2")
- //#pragma GCC optimize("btr-bb-exclusive")
- //#pragma GCC optimize("O0")
- #define int long long
- #define ll long long
- #define ull unsigned long long
- #define all(a) a.begin(), a.end()
- #define pii pair<int, int>
- #define pb push_back
- #define ld long double
- using namespace std;
- //const int INF = 1e13;
- //const int mod = 2600000069;
- //const int p = 179;
- const int mod = 1000000007;
- struct node {
- int max, sum;
- node() {
- max = 1;
- sum = 0;
- }
- node(int max_ , int sum_) {
- max = max_;
- sum = sum_;
- }
- };
- int n;
- vector<node> t;
- node merge(node a, node b) {
- node c;
- if (a.max > b.max) c = a;
- else if (a.max < b.max) c = b;
- else {
- c.max = a.max;
- c.sum = (a.sum + b.sum) % mod;
- }
- return c;
- }
- node get_ans(int v, int l, int r, int askr) {
- if (l >= askr) return node();
- if (r <= askr) return t[v];
- int m = (l + r) / 2;
- return merge(get_ans(2 * v + 1, l, m, askr), get_ans(2 * v + 2, m, r, askr));
- }
- void update(int v, int l, int r, int pos, node val) {
- if (r - l == 1) {
- val.max++;
- if (val.sum == 0) {
- t[v].max = 1;
- t[v].sum++;
- } else t[v] = merge(t[v], val);
- return;
- }
- int m = (l + r) / 2;
- if (pos < m) {
- update(2 * v + 1, l, m, pos, val);
- } else {
- update(2 * v + 2, m, r, pos, val);
- }
- t[v] = merge(t[2 * v + 1], t[2 * v + 2]);
- }
- void build(int v, int l, int r) {
- if (r - l == 1) {
- t[v] = node();
- return;
- }
- int m = (l + r) / 2;
- build(2 * v + 1, l, m);
- build(2 * v + 2, m, r);
- t[v] = merge(t[2 * v + 1], t[2 * v + 2]);
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; i++) cin >> a[i];
- vector<int> b = a;
- b.resize(unique(all(b)) - b.begin());
- int q = b.size();
- map<int, int> ind;
- sort(all(b));
- for (int i = 0; i < q; i++) {
- ind[b[i]] = i;
- }
- // vector<int> cnt(q, 0);
- t.assign(4 * n, node());
- // build(0, 0, n);
- for (int i = 0; i < n; i++) {
- // cnt[ind[a[i]]]++;
- // for (auto k : cnt) cout << k << " ";
- // cout << "\n";
- // cout << "t[0]: " << t[0].max << " " << t[0].sum << "\n";
- // node pref = get_ans(0, 0, n, ind[a[i]]);
- // cout << "pref: " << pref.max << " " << pref.sum << "\n";
- update(0, 0, n, ind[a[i]], get_ans(0, 0, n, ind[a[i]]));
- }
- cout << t[0].sum << "\n";
- }
- /*
- 5
- 1 2 3 4 5
- 6
- 1 1 2 2 3 3
- */
Add Comment
Please, Sign In to add comment