Submission #959181

# Submission time Handle Problem Language Result Execution time Memory
959181 2024-04-07T15:04:32 Z Nelt Global Warming (CEOI18_glo) C++17
100 / 100
457 ms 30548 KB
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
struct SegTree
{
    ll n;
    vector<pair<ll, ll>> st;
    SegTree(ll sz = 0, bool input = false)
    {
        n = sz;
        st.resize((n + 1) << 1, make_pair(-1, (ll)-1e10));
    }
    void set(ll i, pair<ll, ll> val)
    {
        st[i + n - 1] = val;
    }
    void build()
    {
        for (ll i = n - 1; i >= 1; i--)
            st[i] = max(st[i << 1], st[i << 1 | 1]);
    }
    void modify(ll p, pair<ll, ll> val)
    {
        for (st[p += n] = val; p > 1; p >>= 1)
            st[p >> 1] = max(st[p], st[p ^ 1]);
    }
    pair<ll, ll> query(ll l, ll r)
    {
        pair<ll, ll> ans = make_pair(0, -1e10);
        for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1)
        {
            if (l & 1)
                ans = max(ans, st[l++]);
            if (r & 1)
                ans = max(ans, st[--r]);
        }
        return ans;
    }
};
void solve()
{
    ll n, x;
    cin >> n >> x;
    ll a[n];
    for (ll &i : a)
        cin >> i;
    ll b[n];
    memcpy(b, a, sizeof(a));
    sort(b, b + n);
    ll dp[n], dp2[n];
    pair<ll, ll> dp1[n];
    SegTree st(n), st1(n);
    for (ll i = 0; i < n; i++)
    {
        dp[i] = st.query(0, lower_bound(b, b + n, a[i]) - b - 1).first + 1;
        st.modify(lower_bound(b, b + n, a[i]) - b, make_pair(dp[i], 0));
    }
    st = SegTree(n);
    for (ll i = 0; i < n; i++)
    {
        pair<ll, ll> tmp = st.query(0, lower_bound(b, b + n, a[i] + x) - b - 1), tmp1 = st1.query(0, lower_bound(b, b + n, a[i]) - b - 1);
        dp1[i] = max(make_pair(tmp1.first + 1, tmp1.second), make_pair(tmp.first + 1, min(x, max(-x, tmp.second - a[i] + 1))));
        st.modify(lower_bound(b, b + n, a[i]) - b, make_pair(dp[i], a[i]));
        st1.modify(lower_bound(b, b + n, a[i]) - b, dp1[i]);
    }
    st = SegTree(n);
    st1 = SegTree(n);
    ll c[n];
    for (ll i = 0; i < n; i++)
        c[i] = a[i] + dp1[i].second;
    sort(c, c + n);
    for (ll i = 0; i < n; i++)
    {
        pair<ll, ll> tmp = st.query(0, lower_bound(c, c + n, a[i]) - c - 1);
        dp2[i] = tmp.first + 1;
        dp2[i] = max(dp2[i], st.query(0, lower_bound(b, b + n, a[i]) - b - 1).first + 1);
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++)
        ans = max({ans, dp[i], dp2[i], dp1[i].first});
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // precomp();
    // cin >> t;
    for (ll i = 1; i <= t; i++)
        solve();
    cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 414 ms 30436 KB Output is correct
2 Correct 409 ms 30424 KB Output is correct
3 Correct 395 ms 30536 KB Output is correct
4 Correct 409 ms 30524 KB Output is correct
5 Correct 181 ms 29776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 7856 KB Output is correct
2 Correct 86 ms 7960 KB Output is correct
3 Correct 92 ms 7960 KB Output is correct
4 Correct 37 ms 7768 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 44 ms 7764 KB Output is correct
7 Correct 71 ms 7972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 15440 KB Output is correct
2 Correct 152 ms 15436 KB Output is correct
3 Correct 350 ms 30460 KB Output is correct
4 Correct 153 ms 29820 KB Output is correct
5 Correct 96 ms 15112 KB Output is correct
6 Correct 165 ms 28444 KB Output is correct
7 Correct 173 ms 29012 KB Output is correct
8 Correct 131 ms 15444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 414 ms 30436 KB Output is correct
28 Correct 409 ms 30424 KB Output is correct
29 Correct 395 ms 30536 KB Output is correct
30 Correct 409 ms 30524 KB Output is correct
31 Correct 181 ms 29776 KB Output is correct
32 Correct 85 ms 7856 KB Output is correct
33 Correct 86 ms 7960 KB Output is correct
34 Correct 92 ms 7960 KB Output is correct
35 Correct 37 ms 7768 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 44 ms 7764 KB Output is correct
38 Correct 71 ms 7972 KB Output is correct
39 Correct 181 ms 15440 KB Output is correct
40 Correct 152 ms 15436 KB Output is correct
41 Correct 350 ms 30460 KB Output is correct
42 Correct 153 ms 29820 KB Output is correct
43 Correct 96 ms 15112 KB Output is correct
44 Correct 165 ms 28444 KB Output is correct
45 Correct 173 ms 29012 KB Output is correct
46 Correct 131 ms 15444 KB Output is correct
47 Correct 183 ms 15436 KB Output is correct
48 Correct 190 ms 15440 KB Output is correct
49 Correct 457 ms 30436 KB Output is correct
50 Correct 149 ms 29692 KB Output is correct
51 Correct 146 ms 22348 KB Output is correct
52 Correct 210 ms 29812 KB Output is correct
53 Correct 178 ms 29808 KB Output is correct
54 Correct 174 ms 30544 KB Output is correct
55 Correct 324 ms 30548 KB Output is correct