Submission #1096863

#TimeUsernameProblemLanguageResultExecution timeMemory
1096863lmToT27Global Warming (CEOI18_glo)C++17
48 / 100
104 ms4568 KiB
#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] - x) - disVal.begin() + 1; int v1 = lower_bound(all(disVal), a[i]) - 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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...