/* -*- coding: utf-8 -*- * * 992.cc: No.992 最長増加部分列の数え上げ - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_E2 = 1 << 19; // = 524288 const int MOD = 1000000007; const int INF = 1 << 30; /* typedef */ struct Elm { int l, n; Elm() {} Elm(int _l, int _n): l(_l), n(_n) {} Elm operator+(const Elm &e) const { if (l > e.l) return *this; if (l < e.l) return e; return Elm(l, (n + e.n) % MOD); } void print() { printf("(%d,%d)", l, n); } }; template struct SegTreeSum { int n, e2; T nodes[MAX_E2], z; SegTreeSum() {} void init(int _n, T _z) { n = _n; z = _z; for (e2 = 1; e2 < n; e2 <<= 1); fill(nodes, nodes + MAX_E2, z); } T &get(int i) { return nodes[e2 - 1 + i]; } void set(int i, T v) { int j = e2 - 1 + i; nodes[j] = v; while (j > 0) { j = (j - 1) / 2; nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2]; } } T sum_range(int r0, int r1, int k, int i0, int i1) { if (r1 <= i0 || i1 <= r0) return z; if (r0 <= i0 && i1 <= r1) return nodes[k]; int im = (i0 + i1) / 2; T v0 = sum_range(r0, r1, k * 2 + 1, i0, im); T v1 = sum_range(r0, r1, k * 2 + 2, im, i1); return v0 + v1; } T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); } }; /* global variables */ int as[MAX_N], xs[MAX_N + 1]; SegTreeSum st; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i), xs[i] = as[i]; xs[n] = -INF; sort(xs, xs + n + 1); int m = unique(xs, xs + n + 1) - xs; st.init(m, Elm(0, 0)); st.set(0, Elm(0, 1)); for (int i = 0; i < n; i++) { int xi = lower_bound(xs, xs + m, as[i]) - xs; Elm e0 = st.sum_range(0, xi); e0.l++; Elm e = e0 + st.get(xi); st.set(xi, e); } printf("%d\n", st.nodes[0].n); return 0; }