Submission #924283

#TimeUsernameProblemLanguageResultExecution timeMemory
924283NK_Global Warming (CEOI18_glo)C++17
100 / 100
136 ms18892 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define sz(x) int(x.size()) #define pb push_back template<class T> using V = vector<T>; using vi = V<int>; struct BIT { vi A; int N; void init(int n) { N = n; A = vi(N, 0); } void upd(int p, int x) { for(++p;p<=N;p+=p&-p) A[p-1] = max(A[p-1], x); } int get(int r) { int s = 0; for(;r;r-=r&-r) s = max(s, A[r-1]); return s; } }; int main() { cin.tie(0)->sync_with_stdio(0); int N, K; cin >> N >> K; vi A(N), X; for(auto& x : A) { cin >> x; X.pb(x); X.pb(x + K); } sort(begin(X), end(X)); V<BIT> B(2); B[0].init(2 * N), B[1].init(2 * N); V<vi> dp(N, vi(2, 0)); int ans = 0; for(int i = 0; i < N; i++) { int x = lower_bound(begin(X), end(X), A[i]) - begin(X); int xk = lower_bound(begin(X), end(X), A[i] + K) - begin(X); dp[i][0] = B[0].get(x) + 1; dp[i][1] = max(B[0].get(xk), B[1].get(xk)) + 1; // cout << i << " => " << x << " " << xk << endl; // cout << dp[i][0] << " " << dp[i][1] << endl; // cout << endl; ans = max({ans, dp[i][0], dp[i][1]}); B[0].upd(x, dp[i][0]); B[1].upd(xk, dp[i][1]); } cout << ans << nl; exit(0-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...