Submission #714834

# Submission time Handle Problem Language Result Execution time Memory
714834 2023-03-25T10:15:11 Z thimote75 Global Warming (CEOI18_glo) C++14
100 / 100
418 ms 14672 KB
#include <bits/stdc++.h>

using namespace std;

#define num long long

// LIS maintainer
struct LISm {
    map<num, num> d;

    void insert (num id, num res) {
        if (query(id) >= res) return ;
        if (d.find(id) != d.end())
            d.erase(id);

        d.insert({ id, res });

        auto it = d.find(id);
        while (true) {
            it ++;
            if (it == d.end()) break ;
            if ((*it).second > res) break ;

            d.erase((*it).first);
            it = d.find(id);
        }
    }

    // returns the second value of the last iterator such that key < x
    num query (num x) {
        if (d.empty()) return 0;

        auto it = d.lower_bound(x); // first iterator such that key >= x
        if (it == d.begin()) return 0;
        it --; // last iterator such that key < x

        return (*it).second;
    }
    void show () {
        for (auto u : d)
            printf("%lld->%lld ", u.first, u.second);
        printf("\n");
    }
};

int main () {
    LISm lis_0;
    LISm lis_x;

    int nbTemp; num maxDelta;
    cin >> nbTemp >> maxDelta;

    num result = 0;

    for (int idTemp = 0; idTemp < nbTemp; idTemp ++) {
        num temp;
        cin >> temp;
        num temp_x = temp + maxDelta;

        num lis_0_value = 1 + lis_0.query(temp);
        num lis_x_value = 1 + max( lis_0.query(temp_x), lis_x.query(temp_x) );

        //printf("\n--- %d %lld ---\n", idTemp, temp);
        //printf("%d: 0(%lld) +x(%lld)\n", idTemp, lis_0_value, lis_x_value);

        lis_0.insert( temp,   lis_0_value );
        //lis_0.show();
        lis_x.insert( temp_x, lis_x_value );
        //lis_x.show();
    
        result = max(result, lis_0_value);
        result = max(result, lis_x_value);
    }

    cout << result;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 2 ms 308 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 282 ms 2280 KB Output is correct
2 Correct 282 ms 2468 KB Output is correct
3 Correct 283 ms 2212 KB Output is correct
4 Correct 276 ms 2252 KB Output is correct
5 Correct 293 ms 13900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 816 KB Output is correct
2 Correct 64 ms 812 KB Output is correct
3 Correct 65 ms 808 KB Output is correct
4 Correct 57 ms 3664 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 87 ms 3604 KB Output is correct
7 Correct 51 ms 820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 1300 KB Output is correct
2 Correct 124 ms 1228 KB Output is correct
3 Correct 267 ms 2356 KB Output is correct
4 Correct 162 ms 7620 KB Output is correct
5 Correct 183 ms 7064 KB Output is correct
6 Correct 275 ms 13256 KB Output is correct
7 Correct 238 ms 14028 KB Output is correct
8 Correct 103 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 2 ms 308 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 282 ms 2280 KB Output is correct
28 Correct 282 ms 2468 KB Output is correct
29 Correct 283 ms 2212 KB Output is correct
30 Correct 276 ms 2252 KB Output is correct
31 Correct 293 ms 13900 KB Output is correct
32 Correct 66 ms 816 KB Output is correct
33 Correct 64 ms 812 KB Output is correct
34 Correct 65 ms 808 KB Output is correct
35 Correct 57 ms 3664 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 87 ms 3604 KB Output is correct
38 Correct 51 ms 820 KB Output is correct
39 Correct 131 ms 1300 KB Output is correct
40 Correct 124 ms 1228 KB Output is correct
41 Correct 267 ms 2356 KB Output is correct
42 Correct 162 ms 7620 KB Output is correct
43 Correct 183 ms 7064 KB Output is correct
44 Correct 275 ms 13256 KB Output is correct
45 Correct 238 ms 14028 KB Output is correct
46 Correct 103 ms 1228 KB Output is correct
47 Correct 137 ms 1304 KB Output is correct
48 Correct 133 ms 1324 KB Output is correct
49 Correct 282 ms 2380 KB Output is correct
50 Correct 296 ms 13916 KB Output is correct
51 Correct 274 ms 13612 KB Output is correct
52 Correct 418 ms 14116 KB Output is correct
53 Correct 288 ms 14128 KB Output is correct
54 Correct 246 ms 14672 KB Output is correct
55 Correct 230 ms 2240 KB Output is correct