Tree Array
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; # define maxn limit 6int A [maxn]; int n = maxn; struct note {int Val, ord;} B [maxn]; bool CMP (Note A, note B) {return. val <B. val;} int lowbit (int I) {return I & (-I);} int sum (int I) {int sum = 0; while (I> = 1) {sum = (sum + A [I]) % 1000000007; I-= lowbit (I);} return sum;} void Update (int I, int TEM) {While (I <= N) {A [I] + = TEM; A [I] = A [I] % 1000000007; I + = lowbit (I) ;}} int main () {int m; int I; int C [maxn]; int K; while (scanf ("% d ", & M )! = EOF) {for (I = 1; I <= m; I ++) {scanf ("% d", & B [I]. val); B [I]. ord = I;} Sort (B + 1, B + m + 1, CMP); memset (A, 0, sizeof (a); C [B [1]. ord] = 1; for (I = 2; I <= m; I ++) // because the value range is 2 ^ 32, a small processing is performed, scale down the values by sorting. {If (B [I]. val> B [I-1]. val) C [B [I]. ord] = I; elsec [B [I]. ord] = C [B [I-1]. ord] ;}for (I = 1; I <= m; I ++) {k = sum (C [I]); Update (C [I], k + 1);} printf ("% d \ n", sum (m);} return 0 ;}