样例没过,求助
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
stack<int> st;
long long n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
if (x == 1) {
long long l, r;
cin >> l >> r;
st.push(l);
st.push(r);
} else {
long long y;
cin >> y;
long long ans = 0;
while (1) {
if (y <= 0)
break;
long long r = st.top();
st.pop();
long long l = st.top();
st.pop();
if (r - l + 1 <= y) {
ans += (l + r) * (r - l + 1) / 2;
y -= (r - l + 1);
} else {
ans += (l + y) * (y - l + 1) / 2;
st.push(l);
st.push(r - y);
break;
}
}
cout << ans << endl;
}
}
return 0;
}