Submission #533800

# Submission time Handle Problem Language Result Execution time Memory
533800 2022-03-07T10:02:04 Z alextodoran Global Warming (CEOI18_glo) C++17
100 / 100
377 ms 27224 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 200000;
const int T_MAX = (int) 2e9;

int n, x;
int t[N_MAX + 2];
int u[N_MAX + 2];

int before[N_MAX + 2], after[N_MAX + 2];

int beforeFen[N_MAX * 2 + 2], afterFen[N_MAX * 2 + 2];
void update (int Fen[], int pos, int val) {
    for (int i = pos; i <= n * 2; i += i & -i) {
        Fen[i] = max(Fen[i], val);
    }
}
int query (int Fen[], int pos) {
    int ret = 0;
    for (int i = pos; i >= 1; i -= i & -i) {
        ret = max(ret, Fen[i]);
    }
    return ret;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
        u[i] = t[i] + x;
    }

    map <int, int> mp;
    for (int i = 1; i <= n; i++) {
        mp[t[i]]; mp[u[i]];
    }
    int curr = 0;
    for (pair <int, int> _ : mp) {
        mp[_.first] = ++curr;
    }
    for (int i = 1; i <= n; i++) {
        t[i] = mp[t[i]];
        u[i] = mp[u[i]];
    }

    for (int i = 1; i <= n; i++) {
        before[i] = query(beforeFen, t[i] - 1) + 1;
        after[i] = max(query(afterFen, t[i] - 1), query(beforeFen, u[i] - 1)) + 1;
        update(beforeFen, t[i], before[i]);
        update(afterFen, t[i], after[i]);
    }

    cout << query(afterFen, n * 2) << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 236 ms 14388 KB Output is correct
2 Correct 237 ms 16256 KB Output is correct
3 Correct 241 ms 16320 KB Output is correct
4 Correct 227 ms 16320 KB Output is correct
5 Correct 94 ms 10048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 6596 KB Output is correct
2 Correct 57 ms 6516 KB Output is correct
3 Correct 53 ms 6484 KB Output is correct
4 Correct 25 ms 3852 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 27 ms 3840 KB Output is correct
7 Correct 41 ms 5656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 12232 KB Output is correct
2 Correct 141 ms 12004 KB Output is correct
3 Correct 366 ms 23712 KB Output is correct
4 Correct 152 ms 14840 KB Output is correct
5 Correct 94 ms 12608 KB Output is correct
6 Correct 182 ms 23860 KB Output is correct
7 Correct 195 ms 24500 KB Output is correct
8 Correct 109 ms 13020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 236 ms 14388 KB Output is correct
28 Correct 237 ms 16256 KB Output is correct
29 Correct 241 ms 16320 KB Output is correct
30 Correct 227 ms 16320 KB Output is correct
31 Correct 94 ms 10048 KB Output is correct
32 Correct 54 ms 6596 KB Output is correct
33 Correct 57 ms 6516 KB Output is correct
34 Correct 53 ms 6484 KB Output is correct
35 Correct 25 ms 3852 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 27 ms 3840 KB Output is correct
38 Correct 41 ms 5656 KB Output is correct
39 Correct 149 ms 12232 KB Output is correct
40 Correct 141 ms 12004 KB Output is correct
41 Correct 366 ms 23712 KB Output is correct
42 Correct 152 ms 14840 KB Output is correct
43 Correct 94 ms 12608 KB Output is correct
44 Correct 182 ms 23860 KB Output is correct
45 Correct 195 ms 24500 KB Output is correct
46 Correct 109 ms 13020 KB Output is correct
47 Correct 132 ms 13752 KB Output is correct
48 Correct 142 ms 13756 KB Output is correct
49 Correct 377 ms 27224 KB Output is correct
50 Correct 96 ms 15700 KB Output is correct
51 Correct 100 ms 11432 KB Output is correct
52 Correct 144 ms 15680 KB Output is correct
53 Correct 193 ms 25032 KB Output is correct
54 Correct 205 ms 25664 KB Output is correct
55 Correct 210 ms 23640 KB Output is correct