# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093356 | kem | Bouquet (EGOI24_bouquet) | C++14 | 56 ms | 21076 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;
#define NAME "name"
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
const int LIM = 5e5 + 3;
const int INF = 1e9;
const int mod = 1e9 + 7;
int n, l, r;
vector<pii> upd[LIM];
int bit[LIM];
int ans = 1;
void update(int idx, int val)
{
for (; idx < LIM; idx = idx | (idx + 1))
bit[idx] = max(bit[idx], val);
}
int get(int idx)
{
int res = 0;
for (; idx >= 0; idx = (idx & (idx + 1)) - 1)
res = max(res, bit[idx]);
return res;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (ifstream(NAME ".inp"))
{
freopen(NAME ".inp", "r", stdin);
freopen(NAME ".out", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; i++)
{
for (auto v : upd[i])
update(v.fi, v.se);
cin >> l >> r;
int res = get(i - l - 1) + 1;
ans = max(ans, res);
if (i + r + 1 <= n)
upd[i + r + 1].pb({i, res});
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |