#include #include #include #include #include using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define Jungle "subseq" #define MASK(i) (1 << (i)) #define getbit(x, i) (((x) >> (i)) & 1) #define cntbit(x) __builtin_popcount(x) #define _(x) ((x) & -(x)) #define MULTEST \ int numtest; \ read(numtest); \ for (; numtest; --numtest) template void mini(t &a, t b) { if (a > b) a = b; } template void maxi(t &a, t b) { if (a < b) a = b; } const int mod = 1e9 + 7; int add(const int &x, const int &y) { return (1ll * x + y) % mod; } int sub(const int &x, const int &y) { return (1ll * x - y + mod) % mod; } int mul(const int &x, const int &y) { return 1ll * x * y % mod; } template void read(t &x) { cin >> x; } const bool is_debug = 1; const int maxn = 2e5 + 5; int n, a[maxn]; void init(void) { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; } void compress(void) { map store; for (int i = 1; i <= n; ++i) store[a[i]] = 1; int cnt = 0; for (auto &[v, f] : store) f = ++cnt; for (int i = 1; i <= n; ++i) a[i] = store[a[i]]; } struct FenwickTree { pair bit[maxn]; void insert(int x, const pair &p) { for (; x <= n; x += _(x)) if (p.first > bit[x].first) bit[x] = p; else if (p.first == bit[x].first) bit[x].second = add(bit[x].second, p.second); } pair get(int x) { pair ans = {0, 1}; for (; x > 0; x -= _(x)) if (bit[x].first > ans.first) ans = bit[x]; else if (ans.first == bit[x].first) ans.second = add(ans.second, bit[x].second); return ans; } } bit; void solve(void) { init(); compress(); pair res = {0, 1}; for (int i = 1; i <= n; ++i) { pair out = bit.get(a[i] - 1); ++out.first; if (out.first > res.first) res = out; else if (out.first == res.first) res.second = add(out.second, res.second); bit.insert(a[i], out); } cout << res.second << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); if (fopen(Jungle ".inp", "r")) { freopen(Jungle ".inp", "r", stdin); freopen(Jungle ".out", "w", stdout); } // MULTEST solve(); // cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }