제출 #779572

#제출 시각아이디문제언어결과실행 시간메모리
779572Trisanu_DasGlobal Warming (CEOI18_glo)C++17
0 / 100
2081 ms3280 KiB
#include <bits/stdc++.h> using namespace std; int n, x, a[200005], BIT[2][200005], sort_a[200005]; void upd(int k, int idx, int val){ for(int i = idx; i <= n; i += (i & (-i))) BIT[k][i] = max(BIT[k][i], val); } int qry(int k, int idx){ int ans = 0; for(int i = idx; i; i -= (i & (-i))) ans = max(ans, BIT[k][i]); return ans; } int main(){ cin >> n >> x; for(int i = 0; i < n; i++){ cin >> a[i]; sort_a[i] = a[i]; } sort(sort_a, sort_a + n); for(int i = 0; i < n; i++){ int last = lower_bound(sort_a, sort_a + n, a[i]) - sort_a; int a_ = qry(0, last), b = qry(0, lower_bound(sort_a, sort_a + n, a[i] + x) - sort_a), c = qry(1, last); upd(0, last, a_ + 1); upd(1, last, max(b, c) + 1); } cout << qry(1, n) << '\n'; }
#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...