제출 #77909

#제출 시각아이디문제언어결과실행 시간메모리
77909SaboonGlobal Warming (CEOI18_glo)C++14
48 / 100
2063 ms123284 KiB
#include <iostream> #include <queue> #include <bitset> #include <stack> #include <vector> #include <cstring> #include <cmath> #include <unordered_map> #include <map> #include <set> #include <algorithm> #include <iomanip> #define F first #define S second #define PB push_back #define PF push_front #define MP make_pair using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef unsigned long long ull; const int inf = 1e9 + 100; const int maxn = 2e5 + 100; unordered_map <int, int> seg[2]; int dp[maxn][2], a[maxn]; void change (int idx, int val, bool wh) { for (; idx <= inf; idx += idx & -idx) seg[wh][idx] = max (seg[wh][idx], val); } int get (int idx, bool wh) { if (idx == 0) return 0; idx = min (idx, inf - 1); int ret = 0; for (; idx > 0; idx -= idx & -idx) ret = max (ret, seg[wh][idx]); return ret; } int main() { ios_base::sync_with_stdio(false); int n, x; cin >> n >> x; for (int i = 0; i < n; i++) cin >> a[i]; dp[0][0] = 1; dp[0][1] = 1; int ans = 1; change (a[0], dp[0][0], 0); change (a[0], dp[0][1], 1); for (int i = 1; i < n; i++) { dp[i][0] = get (a[i] - 1, 0) + 1; dp[i][1] = get (a[i] + x - 1, 0) + 1; dp[i][1] = max (dp[i][1], get (a[i] - 1, 1) + 1); change (a[i], dp[i][0], 0); change (a[i], dp[i][1], 1); ans = max (ans, dp[i][1]); } cout << ans << endl; }
#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...