Submission #229997

#TimeUsernameProblemLanguageResultExecution timeMemory
229997osaaateiasavtnlZoltan (COCI16_zoltan)C++14
140 / 140
349 ms27960 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC const int N = 2e5 + 7, MOD = 1000 * 1000 * 1000 + 7; int a[N], l[N], r[N], cntl[N], cntr[N], pw[N]; struct Seg { ii tree[N << 2]; ii merge(ii a, ii b) { if (a.f > b.f) return a; if (b.f > a.f) return b; return mp(a.f, (a.s + b.s) % MOD); } void add(int v, int l, int r, int i, ii e) { if (l == r) { tree[v] = merge(tree[v], e); return; } int m = (l + r) >> 1; if (i <= m) add(v * 2 + 1, l, m, i, e); else add(v * 2 + 2, m + 1, r, i, e); tree[v] = merge(tree[v * 2 + 1], tree[v * 2 + 2]); } ii get(int v, int tl, int tr, int l, int r) { if (tr < l || r < tl) return mp(0, 0); if (l <= tl && tr <= r) { //cout << tl << ' ' << tr << " : " << tree[v].f << ' ' << tree[v].s << endl; return tree[v]; } int m = (tl + tr) >> 1; return merge(get(v * 2 + 1, tl, m, l, r), get(v * 2 + 2, m + 1, tr, l, r)); } } L, R; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif pw[0] = 1; for (int i = 1; i < N; ++i) pw[i] = (pw[i - 1] * 2) % MOD; int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; vector <int> c; for (int i = 1; i <= n; ++i) c.app(a[i]); sort(all(c)); c.resize(unique(all(c)) - c.begin()); for (int i = 1; i <= n; ++i) a[i] = lower_bound(all(c), a[i]) - c.begin(); int len = 0; for (int i = n; i; --i) { tie(l[i], cntl[i]) = L.get(0, 0, N, 0, a[i] - 1); ++l[i]; //cout << i << ' ' << l[i] << ' ' << cntl[i] << endl; if (l[i] == 1) cntl[i] = 1; tie(r[i], cntr[i]) = R.get(0, 0, N, a[i] + 1, N); ++r[i]; if (r[i] == 1) cntr[i] = 1; L.add(0, 0, N, a[i], mp(l[i], cntl[i])); R.add(0, 0, N, a[i], mp(r[i], cntr[i])); len = max(len, l[i] + r[i] - 1); } int ans = 0; for (int i = 1; i <= n; ++i) { if (l[i] + r[i] - 1 == len) { ans += (cntl[i] * cntr[i]) % MOD; ans %= MOD; } } ans = ans * pw[n - len] % MOD; cout << len << ' ' << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...