Submission #1119270

#TimeUsernameProblemLanguageResultExecution timeMemory
1119270hamzabcGlobal Warming (CEOI18_glo)C++14
62 / 100
137 ms22044 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define mod 1000000007 #define sp << " " << #define endl << '\n' class lazyporp{ private: vector<long long int> lazy; vector<pair<long long int, long long int>> tree; void push(int node){ if (lazy[node]) tree[node].first = tree[node].second = lazy[node]; lazy[node << 1] = lazy[(node << 1) | 1] = lazy[node]; lazy[node] = 0; } void _update(int say, int at, int l, int r, int s){ push(s); int m = (l + r) >> 1; if (at == -1){ if (l == r){ tree[s].first = tree[s].second = say; return; } if (tree[s << 1].second >= say){ _update(say, at, l, m, s << 1); }else{ _update(say, at, m + 1, r, (s << 1) | 1); } }else{ if (tree[s].first >= say && at >= r){ lazy[s] = say; push(s); return; } if (l == r){ tree[s].first = tree[s].second = say; return; } if (tree[s << 1].second >= say){ _update(say, at, l, m, s << 1); if (at > m) _update(say, at, m + 1, r, (s << 1) | 1); }else{ _update(say, at, m + 1, r, (s << 1) | 1); } } tree[s].first = tree[s << 1].first; tree[s].second = tree[(s << 1) | 1].second; } long long int _count(int l, int r, int s){ push(s); if (tree[s].second != LONG_MAX) return r - l + 1; if (tree[s].first == LONG_MAX) return 0; int m = (l + r) >> 1; return _count(l, m, s << 1) + _count(m + 1, r, (s << 1) | 1); } public: void init(){ lazy.resize(800000); tree.resize(800000, { LONG_MAX, LONG_MAX }); } void update(int say){ _update(say, -1, 0, 200000, 1); } void update(int say, int at){ _update(say, at, 0, 200000, 1); } long long int count(){ return _count(0, 200000, 1); } }; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int N, D; lazyporp LISmanuplated; vector<long long int> LISnormal; LISmanuplated.init(); LISmanuplated.update(0); LISnormal.push_back(0); cin >> N >> D; for (int i = 0; i < N; i++){ long long int in; cin >> in; auto k = lower_bound(all(LISnormal), in + D); LISmanuplated.update(in, k - LISnormal.begin()); k = lower_bound(all(LISnormal), in); if (k == LISnormal.end()){ LISnormal.push_back(in); }else{ *k = in; } LISmanuplated.update(in); } cout << LISmanuplated.count() - 1; return 0; }
#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...