# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092195 | naneosmic | Bouquet (EGOI24_bouquet) | C++14 | 0 ms | 0 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>#define int long long#define endl "\n"using namespace std;signed main(){ int n; cin>>n; vector<int>l(n),r(n),lowerbound,MAX,vals; for(int i=0;i<n;i++){ cin>>l[i]>>r[i]; } int ans=1; MAX.push_back(1); lowerbound.push_back(r[0]); vals.push_back(0); for(int i=1;i<n;i++){ int lower=i-l[i]-1; pair<int,int>NEW; pair<int,int>OLD; OLD.first=MAX[i-1]; OLD.second=lowerbound[i-1]; if(lower<0){ NEW.first=0; NEW.second=i+r[i]; }else{ NEW.second=i+r[i]; if(OLD.first==1){ if(lowerbound[lower]>=i)NEW.first=0; else NEW.first=1; }else{ if(MAX[lower]<=OLD.first-2)NEW.first=OLD.first-2; else{ if(MAX[lower]==OLD.first-1){ if(lowerbound[lower]>=i)NEW.first=OLD.first-2; else NEW.first=OLD.first-1; }else{ if(lowerbound[lower]>=i){ if(lowerbound[vals[vals.size()-2]]>=i)NEW.first=OLD.first-2; else NEW.first=OLD.first-1; }else{ NEW.first=OLD.first; } } } } } NEW.first++; if(NEW.first<OLD.first){ MAX.push_back(OLD.first); lowerbound.push_back(OLD.second); vals[vals.size()-1]++; }else if(NEW.first==OLD.first){ NEW.second=min(NEW.second,OLD.second); MAX.push_back(NEW.first); lowerbound.push_back(NEW.second); vals[vals.size()-1]++; }else{ MAX.push_back(NEW.first); lowerbound.push_back(NEW.second); vals.push_back(i); ans++; } } cout<<ans<<endl;}