1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| #include <iostream> #include <cstring> #include <algorithm> #include <deque> #include <queue> #include <vector> #include <set> #include <map> #include <cmath> #include <bitset> #include <iterator> #include <random>
using namespace std; typedef long long ll; const ll N=static_cast<ll>(2e5)+10; ll query; ll curt,lastHar; vector<pair<ll,ll> > pot; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>query; for(int _=1;_<=query;++_) { ll op,t,h; cin>>op; if(op==1) { if(pot.empty() || pot.back().first!=curt) pot.push_back(make_pair(curt,1)); else pot.back().second+=1; }else if(op==2) { cin>>t; curt+=t; }else { cin>>h; if(curt-h<lastHar) { cout<<0<<endl; continue; } ll l=lower_bound(pot.begin(),pot.end(),make_pair(lastHar,0LL))-pot.begin(); ll r=upper_bound(pot.begin(),pot.end(),make_pair(curt-h,N))-pot.begin()-1; if(r>pot.size()) r=pot.size()-1; ll ans=0; for(int i=l;i<=r;++i) { ans+=pot[i].second; } lastHar=curt-h+1; cout<<ans<<'\n'; } } }
|