QUESTION

“TESTCASE_1”: “4\n1 20 3\n1 40 4\n2 5 5\n1 100 100\n###—###SEPERATOR—###—\n60”, “TESTCASE_2”: “5\n1 776871948 1\n2 53 82\n1 441598129 112\n2 136 166\n1 599424253 258\n###—###SEPERATOR—###—\n0\n441598129”, “TESTCASE_3”: “6\n1 815316197 1\n2 78 81\n1 440942150 176\n2 91 213\n1 28257485 309\n2 267 311\n###—###SEPERATOR—###—\n0\n440942150\n469199635”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

``````#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<ll,ll>
#define fi first
#define se second
int main()
{
ll t,w,T,k,d,ans,r,o,q;
vector<pi> P;
ll S[100002];
vector<pi>::iterator it;
S[d]=0;
cin>>q;
while(q--)
{
cin>>t;
if(t==1)
{
cin>>w>>T;
P.push_back({T,w});
d++;
S[d]=S[d-1]+w;
}
else
{
cin>>k>>T;

//o=0;
pi x;
x.fi=T;
x.se=INT_MIN;
it=upper_bound(P.begin(),P.end(),x);
if(it==P.end())
o=S[d];
else
{
o=S[it-P.begin()];
}
x.fi=T-k;
x.se=INT_MIN;
it=upper_bound(P.begin(),P.end(),x);
if(it==P.end())
r=S[d];
else
{
r=S[it-P.begin()];
}
ans=o-r;
cout<<ans<<endl;
}
}
return 0;
}``````