제출 #248623

#제출 시각아이디문제언어결과실행 시간메모리
248623SortingGlobal Warming (CEOI18_glo)C++14
48 / 100
88 ms3064 KiB
#include <bits/stdc++.h> using namespace std; const int k_N = 2e5 + 3; const int k_Inf = 1e9 + 3; struct Fenwick{ int a[2 * k_N]; void update(int i, int d){ for(++i; i < k_N; i += i & -i) a[i] = max(d, a[i]); } int query(int i){ int ans = 0; for(++i; i >= 1; i -= i & -i) ans = max(a[i], ans); return ans; } }; int n, x; int t[k_N], st[k_N]; Fenwick f[2]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> x; for(int i = 0; i < n; ++i) cin >> t[i]; for(int i = 0; i < n; ++i){ st[2 * i] = t[i]; st[2 * i + 1] = t[i] + x; } sort(st, st + 2 * n); for(int i = 0; i < n; ++i){ int p1 = lower_bound(st, st + 2 * n, t[i]) - st; int p2 = lower_bound(st, st + 2 * n, t[i] + x) - st; int a = f[0].query(p1 - 1); int b = f[0].query(p2 - 1); int c = f[1].query(p2 - 1); f[0].update(p1, a + 1); f[1].update(p2, max(b, c) + 1); } cout << f[1].query(2 * 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...