이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
struct SEG {
ll sz;
vll arr;
void make(ll n) {
for (sz = 1; sz < n; sz <<= 1);
arr.resize(sz*2);
}
void set(ll ind, ll val) {
ind += sz;
arr[ind] = val;
while(ind>>=1) arr[ind] = max(arr[ind*2], arr[ind*2+1]);
}
ll query(ll l, ll r) {
l += sz, r += sz;
ll ans = 0;
while (l <= r) {
if (l % 2 == 1) ans = max(ans, arr[l++]);
if (r % 2 == 0) ans = max(ans, arr[r--]);
l>>=1, r>>=1;
}
return ans;
}
};
int main() {
ll n, d;
cin >> n >> d;
vector<pll> events;
for (int i = 0; i < n; i++) {
ll v;
cin >> v;
events.push_back({v, -i});
}
sort(events.begin(), events.end());
set<ll> inds, inds_bar;
SEG seg;
seg.make(n);
for (auto [val, ind] : events) {
ind = -ind;
auto x = inds.upper_bound(ind);
if (x == inds.begin() || *(--x) + d < ind) {
inds_bar.insert(ind);
}
inds.insert(ind);
auto y = inds_bar.upper_bound(ind);
if (y != inds_bar.end() && *y <= ind + d) {
y = inds_bar.erase(y);
}
ll lb = *--y;
seg.set(ind, 1 + seg.query(lb, ind));
}
cout << seg.query(0, n-1) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |