#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
const int mx = 8e5 + 9;
int s[mx];
int dp[mx];
vector<int>q[mx];
void update(int i, int L, int R, int k, int v) {
if (L == R) {
s[i] = v;
return;
}
int M = (L + R) / 2;
int x = 2 * i + 1, y = x + 1;
if (k <= M) update(x, L, M, k, v);
else update(y, M + 1, R, k, v);
s[i] = max(s[x], s[y]);
return;
}
int query(int i, int L, int R, int l, int r) {
if (L == l && r == R) {
return s[i];
}
int M = (L + R) / 2;
int x = 2 * i + 1, y = x + 1;
if (r <= M) return query(x, L, M, l, r);
else if (M + 1 <= l) return query(y, M + 1, R, l, r);
else return max(query(x, L, M, l, M) , query(y, M + 1, R, M + 1, r));
}
signed main() {
int n; cin >> n;
vector<int> l(n + 1);
vector<int> r(n + 1);
for (int i = 1; i <= n; i++) {
cin >> l[i] >> r[i];
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int ll = i - l[i];
int rr = i + r[i];
dp[i] = query(0, 0, n, 0, max(0LL, ll - 1)) + 1;
ans = max(ans, dp[i]);
if (rr <= n) q[rr].push_back(i);
for (int j : q[i]) {
update(0, 0, n, j, dp[j]);
}
}
cout << ans << endl;
return 0;
}
# | 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... |