Submission #1096859

# Submission time Handle Problem Language Result Execution time Memory
1096859 2024-10-05T09:36:16 Z lmToT27 Global Warming (CEOI18_glo) C++17
0 / 100
98 ms 4564 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[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;

template <typename dataType>
inline void compress(vector <dataType> &x) {
        sort(all(x));
        x.erase(unique(all(x)), x.end());
}

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);
        }
        compress(disVal);
        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 + max(F0.get(v0 - 1), F1.get(v0 - 1));
                int dp1 = 1 + F0.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 1 ms 2392 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 4564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3168 KB Output is correct
2 Correct 21 ms 3040 KB Output is correct
3 Correct 21 ms 3056 KB Output is correct
4 Incorrect 10 ms 3036 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 3544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -