제출 #1313186

#제출 시각아이디문제언어결과실행 시간메모리
1313186huoiGlobal Warming (CEOI18_glo)C++17
0 / 100
22 ms13000 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF struct FenwickTree { int n; vector<int> t; FenwickTree(int n) : n(n), t(n) {} int lsb(int x) { return x & -x; } void update(int p, int x) { while (p <= n) { t[p] = max(t[p], x); p += lsb(p); } } int query(int p) { int ans = 0; while (p > 0) { ans = max(ans, t[p]); p -= lsb(p); } return ans; } }; void solve() { int n, x; cin >> n >> x; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int ans = 1; vector<FenwickTree> ft(2, FenwickTree(10000)); vector<vector<int>> dp(n + 1, vector<int>(2, 1)); for (int i = 1; i <= n; i++) { dp[i][0] = ft[0].query(a[i] - 1) + 1; dp[i][1] = max(ft[0].query(a[i] - x - 1), ft[1].query(a[i] - 1)) + 1; ft[0].update(a[i], dp[i][0]); ft[1].update(a[i], dp[i][1]); ans = max(ans, max(dp[i][0], dp[i][1])); } cout << ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); 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...