# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
779570 | Trisanu_Das | Global Warming (CEOI18_glo) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
cou