Submission #991275

# Submission time Handle Problem Language Result Execution time Memory
991275 2024-06-01T17:21:03 Z LOLOLO Zoltan (COCI16_zoltan) C++17
140 / 140
266 ms 24640 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 2e5 + 10;
int a[N], mod = 1e9 + 7;

struct ST{
    vector <pair <int, int>> seg;
    void ass(int n) {
        seg.assign(n * 4 + 100, {0, 0});
    }

    void upd(int id, int l, int r, int p, pair <int, ll> val) {
        if (l == r) {
            if (seg[id].f < val.f) {
                seg[id] = val;
            } else if (seg[id].f == val.f) {
                seg[id].s = (seg[id].s + val.s) % mod;
            }

            return;
        }

        int m = (l + r) / 2;
        if (m >= p) {
            upd(id * 2, l, m, p, val);
        } else {
            upd(id * 2 + 1, m + 1, r, p, val);
        }

        seg[id].f = max(seg[id * 2].f, seg[id * 2 + 1].f);
        if (seg[id * 2].f == seg[id * 2 + 1].f) {
            seg[id].s = (seg[id * 2].s + seg[id * 2 + 1].s) % mod;
        } else {
            seg[id].s = seg[id * 2].f > seg[id * 2 + 1].f ? seg[id * 2].s : seg[id * 2 + 1].s;
        }
    }

    pair <int, int> get(int id, int l, int r, int u, int v) {
        if (l > v || r < u || u > v)
            return {0, 0};

        if (l >= u && r <= v)
            return seg[id];

        int m = (l + r) / 2;
        pair <int, int> L = get(id * 2, l, m, u, v), R = get(id * 2 + 1, m + 1, r, u, v);
        if (L.f == R.f) {
            return {L.f, (L.s + R.s) % mod};
        } 

        return max(L, R);
    }
};

ll solve() {
    int n;
    cin >> n;

    int timer = 1;
    map <int, int> mp;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mp[a[i]];
    }

    for (auto &x : mp) {
        x.s = timer;
        timer++;
    }

    for (int i = 1; i <= n; i++) {
        a[i] = mp[a[i]];
    }

    ST lds, lis;
    lds.ass(n);
    lis.ass(n);

    pair <int, int> ans = {0, 0};

    for (int i = n; i >= 1; i--) {
        pair <int, ll> A = lds.get(1, 1, n, a[i] + 1, n), B = lis.get(1, 1, n, 1, a[i] - 1);
        A.f++, B.f++;
        if (A.s == 0)
            A.s++;

        if (B.s == 0)
            B.s++;

        pair <ll, ll> C = {A.f + B.f - 1, (A.s * B.s) % mod};
        if (ans.f < C.f) {
            ans = C;
        } else if (ans.f == C.f) {
            ans.s = (ans.s + C.s) % mod;
        }

        lds.upd(1, 1, n, a[i], A);
        lis.upd(1, 1, n, a[i], B);
    }

    int tot = ans.s;
    for (int i = 1; i <= n - ans.f; i++) {
        tot = (tot + tot) % mod;
    }

    cout << ans.f << " " << tot << '\n';
    return 0;
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
 
    int t = 1;
    //cin >> t;
 
    while (t--) {
        solve();
    }
 
    return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 484 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 160 ms 19424 KB Output is correct
12 Correct 139 ms 16976 KB Output is correct
13 Correct 119 ms 15912 KB Output is correct
14 Correct 169 ms 17232 KB Output is correct
15 Correct 226 ms 21360 KB Output is correct
16 Correct 266 ms 24640 KB Output is correct
17 Correct 161 ms 22864 KB Output is correct
18 Correct 162 ms 22864 KB Output is correct
19 Correct 162 ms 22864 KB Output is correct
20 Correct 174 ms 22864 KB Output is correct