Submission #1109814

# Submission time Handle Problem Language Result Execution time Memory
1109814 2024-11-07T17:09:41 Z Vkrisztian01 Global Warming (CEOI18_glo) C++14
100 / 100
616 ms 48728 KB
#include <iostream>
#include <bits/stdc++.h>
#define lsb(s) (s & -s)
typedef long long ll;
const int maxn = 5 * 1e5;

using namespace std;

class SegmentTree
{
private:
    vector<int> t;

public:
    SegmentTree()
    {
        t.assign(4 * maxn, 0);
    }

    int query(int node, int tl, int tr, int l, int r)
    {
        if (l > r) return 0;
        if (tl == l && tr == r) return t[node];

        int tm = (tl + tr) / 2;

        return max(query(node * 2, tl, tm, l, min(r, tm)),
                   query(node * 2 + 1, tm + 1, tr, max(tm + 1, l), r));
    }

    void change(int node, int tl, int tr, int i, int k)
    {
        if (tl == tr) t[node] = max(t[node], k);
        else
        {
            int tm = (tl + tr) / 2;

            if (i <= tm) change(node * 2, tl, tm, i, k);
            else change(node * 2 + 1, tm + 1, tr, i, k);

            t[node] = max(t[node * 2], t[node * 2 + 1]);
        }
    }
};

int main()
{
    int n, x;
    cin >> n >> x;

    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    vector<ll> b;
    for (int i = 0; i < n; i++)
    {
        b.push_back(a[i]);
        b.push_back(a[i] - x);
    }

    sort(b.begin(), b.end());
    int cnt = 0;
    map<ll, ll> s;
    for (auto value : b)
        if (s[value] == 0)
            s[value] = ++cnt;

    SegmentTree st1;
    SegmentTree st2;

    for(int v : a)
    {
        int k = s[v] ;
        int l = st1.query(1 , 1 , maxn , 1 , k - 1) ;
        st1.change(1 , 1 , maxn , k , l + 1) ;

        int k2 = s[v - x] ;
        int l2 = st2.query(1 , 1 , maxn , 1 , k - 1) ;
        st2.change(1 , 1 , maxn , k , l2 + 1) ;
        st2.change(1 , 1 , maxn , k2 , l + 1) ;

    }

    int ans = max( st1.query(1 , 1 , maxn , 1 , maxn) ,
                  st2.query(1 , 1 , maxn , 1 , maxn) ) ;

    cout << ans ;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15952 KB Output is correct
2 Correct 4 ms 15952 KB Output is correct
3 Correct 5 ms 15952 KB Output is correct
4 Correct 5 ms 15952 KB Output is correct
5 Correct 5 ms 15952 KB Output is correct
6 Correct 5 ms 15952 KB Output is correct
7 Correct 5 ms 15952 KB Output is correct
8 Correct 5 ms 15952 KB Output is correct
9 Correct 4 ms 15952 KB Output is correct
10 Correct 5 ms 15964 KB Output is correct
11 Correct 4 ms 15952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15952 KB Output is correct
2 Correct 4 ms 15952 KB Output is correct
3 Correct 5 ms 15952 KB Output is correct
4 Correct 5 ms 15952 KB Output is correct
5 Correct 5 ms 15952 KB Output is correct
6 Correct 5 ms 15952 KB Output is correct
7 Correct 5 ms 15952 KB Output is correct
8 Correct 5 ms 15952 KB Output is correct
9 Correct 4 ms 15952 KB Output is correct
10 Correct 5 ms 15964 KB Output is correct
11 Correct 4 ms 15952 KB Output is correct
12 Correct 6 ms 16232 KB Output is correct
13 Correct 4 ms 15952 KB Output is correct
14 Correct 4 ms 16056 KB Output is correct
15 Correct 4 ms 15952 KB Output is correct
16 Correct 5 ms 15952 KB Output is correct
17 Correct 5 ms 15952 KB Output is correct
18 Correct 6 ms 15952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15952 KB Output is correct
2 Correct 4 ms 15952 KB Output is correct
3 Correct 5 ms 15952 KB Output is correct
4 Correct 5 ms 15952 KB Output is correct
5 Correct 5 ms 15952 KB Output is correct
6 Correct 5 ms 15952 KB Output is correct
7 Correct 5 ms 15952 KB Output is correct
8 Correct 5 ms 15952 KB Output is correct
9 Correct 4 ms 15952 KB Output is correct
10 Correct 5 ms 15964 KB Output is correct
11 Correct 4 ms 15952 KB Output is correct
12 Correct 6 ms 16232 KB Output is correct
13 Correct 4 ms 15952 KB Output is correct
14 Correct 4 ms 16056 KB Output is correct
15 Correct 4 ms 15952 KB Output is correct
16 Correct 5 ms 15952 KB Output is correct
17 Correct 5 ms 15952 KB Output is correct
18 Correct 6 ms 15952 KB Output is correct
19 Correct 6 ms 16208 KB Output is correct
20 Correct 6 ms 16380 KB Output is correct
21 Correct 6 ms 16208 KB Output is correct
22 Correct 6 ms 16152 KB Output is correct
23 Correct 6 ms 15952 KB Output is correct
24 Correct 6 ms 15952 KB Output is correct
25 Correct 6 ms 15952 KB Output is correct
26 Correct 6 ms 16128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 499 ms 36160 KB Output is correct
2 Correct 406 ms 36016 KB Output is correct
3 Correct 373 ms 36132 KB Output is correct
4 Correct 384 ms 36016 KB Output is correct
5 Correct 185 ms 29092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 23996 KB Output is correct
2 Correct 109 ms 24008 KB Output is correct
3 Correct 106 ms 23996 KB Output is correct
4 Correct 57 ms 20676 KB Output is correct
5 Correct 4 ms 15952 KB Output is correct
6 Correct 76 ms 20676 KB Output is correct
7 Correct 94 ms 22972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 32388 KB Output is correct
2 Correct 254 ms 32268 KB Output is correct
3 Correct 616 ms 48728 KB Output is correct
4 Correct 263 ms 35232 KB Output is correct
5 Correct 165 ms 31940 KB Output is correct
6 Correct 370 ms 46668 KB Output is correct
7 Correct 339 ms 47284 KB Output is correct
8 Correct 245 ms 32440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15952 KB Output is correct
2 Correct 4 ms 15952 KB Output is correct
3 Correct 5 ms 15952 KB Output is correct
4 Correct 5 ms 15952 KB Output is correct
5 Correct 5 ms 15952 KB Output is correct
6 Correct 5 ms 15952 KB Output is correct
7 Correct 5 ms 15952 KB Output is correct
8 Correct 5 ms 15952 KB Output is correct
9 Correct 4 ms 15952 KB Output is correct
10 Correct 5 ms 15964 KB Output is correct
11 Correct 4 ms 15952 KB Output is correct
12 Correct 6 ms 16232 KB Output is correct
13 Correct 4 ms 15952 KB Output is correct
14 Correct 4 ms 16056 KB Output is correct
15 Correct 4 ms 15952 KB Output is correct
16 Correct 5 ms 15952 KB Output is correct
17 Correct 5 ms 15952 KB Output is correct
18 Correct 6 ms 15952 KB Output is correct
19 Correct 6 ms 16208 KB Output is correct
20 Correct 6 ms 16380 KB Output is correct
21 Correct 6 ms 16208 KB Output is correct
22 Correct 6 ms 16152 KB Output is correct
23 Correct 6 ms 15952 KB Output is correct
24 Correct 6 ms 15952 KB Output is correct
25 Correct 6 ms 15952 KB Output is correct
26 Correct 6 ms 16128 KB Output is correct
27 Correct 499 ms 36160 KB Output is correct
28 Correct 406 ms 36016 KB Output is correct
29 Correct 373 ms 36132 KB Output is correct
30 Correct 384 ms 36016 KB Output is correct
31 Correct 185 ms 29092 KB Output is correct
32 Correct 111 ms 23996 KB Output is correct
33 Correct 109 ms 24008 KB Output is correct
34 Correct 106 ms 23996 KB Output is correct
35 Correct 57 ms 20676 KB Output is correct
36 Correct 4 ms 15952 KB Output is correct
37 Correct 76 ms 20676 KB Output is correct
38 Correct 94 ms 22972 KB Output is correct
39 Correct 321 ms 32388 KB Output is correct
40 Correct 254 ms 32268 KB Output is correct
41 Correct 616 ms 48728 KB Output is correct
42 Correct 263 ms 35232 KB Output is correct
43 Correct 165 ms 31940 KB Output is correct
44 Correct 370 ms 46668 KB Output is correct
45 Correct 339 ms 47284 KB Output is correct
46 Correct 245 ms 32440 KB Output is correct
47 Correct 276 ms 32192 KB Output is correct
48 Correct 228 ms 32184 KB Output is correct
49 Correct 599 ms 48560 KB Output is correct
50 Correct 244 ms 35236 KB Output is correct
51 Correct 205 ms 31408 KB Output is correct
52 Correct 277 ms 35616 KB Output is correct
53 Correct 320 ms 48048 KB Output is correct
54 Correct 370 ms 48560 KB Output is correct
55 Correct 440 ms 44636 KB Output is correct