제출 #1063015

#제출 시각아이디문제언어결과실행 시간메모리
1063015belgianbotBouquet (EGOI24_bouquet)C++17
100 / 100
76 ms8192 KiB
#include <bits/stdc++.h> using namespace std; int N = 4 * 1e5 + 1; int n; vector<int> t(N); vector<int>l, r; void build() { for (int i = n; i > 0; i--) t[i] = max(t[i << 1], t[i << 1 | 1]); } void update(int pos, int value) { for (t[pos += n] = value, pos >>= 1; pos > 0; pos >>= 1) t[pos] = max(t[pos << 1], t[pos << 1 | 1]); } int query(int l, int r) { l += n; r += n; int res = 0; for (; l < r; l >>= 1, r >>= 1) { if (l&1) res = max(res, t[l++]); if (r&1) res = max(res, t[--r]); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; l.resize(n); r.resize(n); for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; t[i + n] = 0; } build(); vector<int> value(n); int ans = 0; priority_queue <pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> q; for (int i = 0; i < n; i++) { q.push(make_pair(r[i] + i, i)); while (!q.empty() && i > q.top().first) { int j = q.top().second; update(j, value[j]); q.pop(); } value[i] = query(0, max(i - l[i], 0)) + 1; ans = max(ans, value[i]); } cout <<ans << '\n'; return 0; }
#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...