Submission #1096864

# Submission time Handle Problem Language Result Execution time Memory
1096864 2024-10-05T09:54:38 Z lmToT27 Global Warming (CEOI18_glo) C++17
100 / 100
106 ms 8132 KB
#include <bits/stdc++.h>
#define all(dataStructure) dataStructure.begin(),dataStructure.end()
#define ll long long
 
using namespace std;
namespace std {
        template <typename T, int D>
        struct _vector : public vector <_vector <T, D - 1>> {
                static_assert(D >= 1, "Dimension must be positive!");
                template <typename... Args>
                _vector(int n = 0, Args... args) : vector <_vector <T, D - 1>> (n, _vector <T, D - 1> (args...)) {}
        };
        // _vector <int, 3> a(n, m, k);: int a[n][m][k].
        // _vector <int, 3> a(n, m, k, x);: int a[n][m][k] initialized with x.
        template <typename T>
        struct _vector <T, 1> : public vector <T> {
                _vector(int n = 0, const T& val = T()) : vector <T> (n, val) {}
        };
}
 
const int MAX = 2e5 + 3;
const ll MOD[] = {1000000007, 998244353};
 
int n, x;
int a[MAX];
 
struct FenwickTree {
        int bit[2 * MAX];
 
        void update(int u, int val) {
                for (; u <= 2 * n; u += u & -u) {
                        bit[u] = max(bit[u], val);
                }
        }
 
        int get(int u) {
                int res = 0;
                for (; u > 0; u -= u & -u) res = max(res, bit[u]);
                return res;
        }
} F0, F1;
 
 
void Solve() {
        vector <int> disVal;
        cin >> n >> x;
        for (int i = 1; i <= n; i++) {
                cin >> a[i];
                disVal.push_back(a[i]);
                disVal.push_back(a[i] + x);
        }

        sort(all(disVal));
        disVal.erase(unique(all(disVal)), disVal.end());

        int ans = 0;
        
        for (int i = 1; i <= n; i++) {
                int v0 = lower_bound(all(disVal), a[i]) - disVal.begin() + 1;
                int v1 = lower_bound(all(disVal), a[i] + x) - disVal.begin() + 1;
                int dp0 = 1 + F0.get(v0 - 1);
                int dp1 = 1 + max(F0.get(v1 - 1), F1.get(v1 - 1));
                ans = max({ans, dp0, dp1});
                F0.update(v0, dp0);
                F1.update(v1, dp1);
        }

        cout << ans;
}
 
int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
 
        #define TASK "TASK"
        if (fopen(TASK".INP", "r")) {
                freopen(TASK".INP", "r", stdin);
                freopen(TASK".OUT", "w", stdout);
        }
        
        /* int TEST = 1; cin >> TEST; while (TEST--) */ Solve();
 
        cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
        return 0;
}

Compilation message

glo.cpp: In function 'int32_t main()':
glo.cpp:77:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |                 freopen(TASK".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:78:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |                 freopen(TASK".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 4560 KB Output is correct
2 Correct 92 ms 6464 KB Output is correct
3 Correct 90 ms 6348 KB Output is correct
4 Correct 94 ms 6236 KB Output is correct
5 Correct 39 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1752 KB Output is correct
2 Correct 21 ms 1756 KB Output is correct
3 Correct 22 ms 1756 KB Output is correct
4 Correct 10 ms 1552 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 11 ms 1464 KB Output is correct
7 Correct 17 ms 1756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2364 KB Output is correct
2 Correct 48 ms 2520 KB Output is correct
3 Correct 106 ms 4356 KB Output is correct
4 Correct 49 ms 4880 KB Output is correct
5 Correct 27 ms 3032 KB Output is correct
6 Correct 47 ms 5316 KB Output is correct
7 Correct 51 ms 6084 KB Output is correct
8 Correct 38 ms 3536 KB Output is correct
# 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 92 ms 4560 KB Output is correct
28 Correct 92 ms 6464 KB Output is correct
29 Correct 90 ms 6348 KB Output is correct
30 Correct 94 ms 6236 KB Output is correct
31 Correct 39 ms 4688 KB Output is correct
32 Correct 21 ms 1752 KB Output is correct
33 Correct 21 ms 1756 KB Output is correct
34 Correct 22 ms 1756 KB Output is correct
35 Correct 10 ms 1552 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 11 ms 1464 KB Output is correct
38 Correct 17 ms 1756 KB Output is correct
39 Correct 49 ms 2364 KB Output is correct
40 Correct 48 ms 2520 KB Output is correct
41 Correct 106 ms 4356 KB Output is correct
42 Correct 49 ms 4880 KB Output is correct
43 Correct 27 ms 3032 KB Output is correct
44 Correct 47 ms 5316 KB Output is correct
45 Correct 51 ms 6084 KB Output is correct
46 Correct 38 ms 3536 KB Output is correct
47 Correct 45 ms 4300 KB Output is correct
48 Correct 45 ms 4308 KB Output is correct
49 Correct 99 ms 8132 KB Output is correct
50 Correct 41 ms 5576 KB Output is correct
51 Correct 40 ms 4044 KB Output is correct
52 Correct 49 ms 5580 KB Output is correct
53 Correct 50 ms 5728 KB Output is correct
54 Correct 55 ms 6424 KB Output is correct
55 Correct 80 ms 7464 KB Output is correct