# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1057416 | Mr_Husanboy | Bouquet (EGOI24_bouquet) | C++17 | 61 ms | 16260 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
return a.size();
}
using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1e5 + 1;
void yesno(bool ok){
cout << (ok ? "Yes\n" : "No\n");
}
struct SegmentTree{
int n;
vector<int> t;
SegmentTree (int n) : n(n), t(2 * n){}
SegmentTree () {}
int merge(int a, int b){
return max(a, b);
}
void upd(int i, int val){
i += n;
t[i] = val;
for(i /= 2; i > 0; i /= 2){
t[i] = merge(t[i * 2], t[i * 2 + 1]);
}
}
int get(int l, int r){
l += n; r += n;
int res = 0;
while(l <= r){
if(l & 1){
res = merge(res, t[l ++]);
}
if(!(r & 1)){
res = merge(res, t[r --]);
}
l /= 2; r /= 2;
}
return res;
}
};
void solve(){
int n; cin >> n;
vector<int> l(n), r(n);
for(int i = 0; i< n; i ++){
cin >> l[i] >> r[i];
}
SegmentTree t(n);
vector<vector<pair<int,int>>> close(n);
int mx = 0;
for(int i = 0; i < n; i ++){
int res = t.get(0, i - l[i] - 1) + 1;
mx = max(mx, res);
if(i + r[i] < n){
close[i + r[i]].push_back({i, res});
}
for(auto [j, val] : close[i]){
t.upd(j, val);
}
}
cout << mx;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
auto start = chrono::high_resolution_clock::now();
#ifndef LOCAL
if(fileio.size()){
freopen((fileio + ".in").c_str(), "r", stdin);
freopen((fileio + ".out").c_str(), "w", stdout);
}
#endif
int testcases = 1;
#ifdef Tests
cin >> testcases;
#endif
while(testcases --){
solve();
if(testcases) cout << '\n';
#ifdef LOCAL
else cout << '\n';
cout << "_________________________" << endl;
#endif
}
#ifdef LOCAL
auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
#endif
return 0;
}
컴파일 시 표준 에러 (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... |