#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//mt19937 gen(time(NULL));
mt19937 gen(200);
struct node {
pair<int, int> f, s;
node *le, *ri;
ll mn, res;
int tl, tr;
node() {
mn = 228;
}
node(int l, int r) {
tl = l; tr = r;
mn = 228;
if (l == r) return;
le = new node(l, (l+r)/2);
ri = new node((l+r)/2+1, r);
}
node (node* a, node* b) {
le = a; ri = b;
tl = le->tl; tr = ri->tr;
if (le->mn == 228) {
res = ri->res;
mn = ri->mn;
f = ri->f;
s = ri->s;
return;
}
if (ri->mn == 228) {
res = le->res;
mn = le->mn;
f = le->f;
s = le->s;
return;
}
f = le->f; s = ri->s;
ll del = 1ll*le->s.second*(ri->f.first-le->s.first);
res = le->res+del+ri->res;
mn = min(le->mn, le->res+del);
mn = min(mn, ri->mn+le->res+del);
}
void combine() {
node tmp(le, ri);
*this = tmp;
}
void update(int id, int time, int speed) {
if (tl == tr) {
mn = res = 0;
f.first = s.first = time;
f.second = s.second = speed;
return;
}
if (id <= (tl+tr)/2)
le->update(id, time, speed);
else
ri->update(id, time, speed);
combine();
}
void del(int id) {
if (tl == tr) {
mn = 228;
return;
}
if (id <= (tl+tr)/2)
le->del(id);
else
ri->del(id);
combine();
}
node* get_seg(int l, int r) {
if (tr < l || r < tl) return new node();
if (l <= tl && tr <= r) {
return this;;
}
return new node(le->get_seg(l, r), ri->get_seg(l, r));
}
long double simulate(int r, ll v) {
if (mn == 228) return -1;
if (v+mn > 0 && v+res+1ll*s.second*(r-s.first) > 0) return -1;
if (f == s) return s.first-(long double)v/s.second;
if (le->mn == 228) return ri->simulate(r, v);
long double to = le->simulate(le->s.first, v);
if (to != -1) return to;
v += le->res;
ll del = 1ll*le->s.second*((ri->mn==228?r:ri->f.first)-le->s.first);
if (v+del <= 0) return le->s.first-(long double)v/le->s.second;
v += del;
return ri->simulate(r, v);
}
long double query(int l, int r, int rr, ll v) {
node* t = get_seg(l, r);
return t->simulate(rr, v);
}
};
struct query{
int time, speed, start;
int l, r, type;
query() {}
};
vector <int> pos;
vector <query> q;
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
cout.precision(7);
int qq; cin >> qq;
q.resize(qq);
for (int i = 0; i < qq; ++i) {
cin >> q[i].type;
if (q[i].type == 1) {
cin >> q[i].time >> q[i].speed;
pos.push_back(q[i].time);
}
if (q[i].type == 2) {
cin >> q[i].time;
}
if (q[i].type == 3) {
cin >> q[i].l >> q[i].r >> q[i].start;
}
}
sort(pos.begin(), pos.end());
pos.erase(unique(pos.begin(), pos.end()), pos.end());
if (pos.size() == 0) pos.push_back(0);
node* t = new node(0, pos.size()-1);
for (int i = 0; i < qq; ++i) {
if (q[i].type == 1) {
int id = lower_bound(pos.begin(), pos.end(), q[i].time)-pos.begin();
t->update(id, q[i].time, q[i].speed);
}
if (q[i].type == 2) {
int id = lower_bound(pos.begin(), pos.end(), q[i].time)-pos.begin();
t->del(id);
}
if (q[i].type == 3) {
int l = lower_bound(pos.begin(), pos.end(), q[i].l)-pos.begin();
int r = --upper_bound(pos.begin(), pos.end(), q[i].r)-pos.begin();
if (q[i].start == 0)
cout << fixed << q[i].l << '\n';
else
cout << fixed << t->query(l, r, q[i].r, q[i].start) << '\n';
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKLy9tdDE5OTM3IGdlbih0aW1lKE5VTEwpKTsKbXQxOTkzNyBnZW4oMjAwKTsKCnN0cnVjdCBub2RlIHsKICAgIHBhaXI8aW50LCBpbnQ+IGYsIHM7CiAgICBub2RlICpsZSwgKnJpOwogICAgbGwgbW4sIHJlczsKICAgIGludCB0bCwgdHI7CiAgICBub2RlKCkgewogICAgICAgIG1uID0gMjI4OwogICAgfQogICAgbm9kZShpbnQgbCwgaW50IHIpIHsKICAgICAgICB0bCA9IGw7IHRyID0gcjsKICAgICAgICBtbiA9IDIyODsKICAgICAgICBpZiAobCA9PSByKSByZXR1cm47CiAgICAgICAgbGUgPSBuZXcgbm9kZShsLCAobCtyKS8yKTsKICAgICAgICByaSA9IG5ldyBub2RlKChsK3IpLzIrMSwgcik7CiAgICB9CiAgICBub2RlIChub2RlKiBhLCBub2RlKiBiKSB7CiAgICAgICAgbGUgPSBhOyByaSA9IGI7CiAgICAgICAgdGwgPSBsZS0+dGw7IHRyID0gcmktPnRyOwogICAgICAgIGlmIChsZS0+bW4gPT0gMjI4KSB7CiAgICAgICAgICAgIHJlcyA9IHJpLT5yZXM7CiAgICAgICAgICAgIG1uID0gcmktPm1uOwogICAgICAgICAgICBmID0gcmktPmY7CiAgICAgICAgICAgIHMgPSByaS0+czsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBpZiAocmktPm1uID09IDIyOCkgewogICAgICAgICAgICByZXMgPSBsZS0+cmVzOwogICAgICAgICAgICBtbiA9IGxlLT5tbjsKICAgICAgICAgICAgZiA9IGxlLT5mOwogICAgICAgICAgICBzID0gbGUtPnM7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgZiA9IGxlLT5mOyBzID0gcmktPnM7CiAgICAgICAgbGwgZGVsID0gMWxsKmxlLT5zLnNlY29uZCoocmktPmYuZmlyc3QtbGUtPnMuZmlyc3QpOwogICAgICAgIHJlcyA9IGxlLT5yZXMrZGVsK3JpLT5yZXM7CiAgICAgICAgbW4gPSBtaW4obGUtPm1uLCBsZS0+cmVzK2RlbCk7CiAgICAgICAgbW4gPSBtaW4obW4sIHJpLT5tbitsZS0+cmVzK2RlbCk7CiAgICB9CiAgICB2b2lkIGNvbWJpbmUoKSB7CiAgICAgICAgbm9kZSB0bXAobGUsIHJpKTsKICAgICAgICAqdGhpcyA9IHRtcDsKICAgIH0KICAgIHZvaWQgdXBkYXRlKGludCBpZCwgaW50IHRpbWUsIGludCBzcGVlZCkgewogICAgICAgIGlmICh0bCA9PSB0cikgewogICAgICAgICAgICBtbiA9IHJlcyA9IDA7CiAgICAgICAgICAgIGYuZmlyc3QgPSBzLmZpcnN0ID0gdGltZTsKICAgICAgICAgICAgZi5zZWNvbmQgPSBzLnNlY29uZCA9IHNwZWVkOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGlmIChpZCA8PSAodGwrdHIpLzIpCiAgICAgICAgICAgIGxlLT51cGRhdGUoaWQsIHRpbWUsIHNwZWVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICAgIHJpLT51cGRhdGUoaWQsIHRpbWUsIHNwZWVkKTsKICAgICAgICBjb21iaW5lKCk7CiAgICB9CiAgICB2b2lkIGRlbChpbnQgaWQpIHsKICAgICAgICBpZiAodGwgPT0gdHIpIHsKICAgICAgICAgICAgbW4gPSAyMjg7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgaWYgKGlkIDw9ICh0bCt0cikvMikKICAgICAgICAgICAgbGUtPmRlbChpZCk7CiAgICAgICAgZWxzZQogICAgICAgICAgICByaS0+ZGVsKGlkKTsKICAgICAgICBjb21iaW5lKCk7CiAgICB9CiAgICBub2RlKiBnZXRfc2VnKGludCBsLCBpbnQgcikgewogICAgICAgIGlmICh0ciA8IGwgfHwgciA8IHRsKSByZXR1cm4gbmV3IG5vZGUoKTsKICAgICAgICBpZiAobCA8PSB0bCAmJiB0ciA8PSByKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzOzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG5ldyBub2RlKGxlLT5nZXRfc2VnKGwsIHIpLCByaS0+Z2V0X3NlZyhsLCByKSk7CiAgICB9CiAgICBsb25nIGRvdWJsZSBzaW11bGF0ZShpbnQgciwgbGwgdikgewogICAgICAgIGlmIChtbiA9PSAyMjgpIHJldHVybiAtMTsKICAgICAgICBpZiAodittbiA+IDAgJiYgdityZXMrMWxsKnMuc2Vjb25kKihyLXMuZmlyc3QpID4gMCk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AgICNlbmRpZiAvLyBMT0NBTAogICAgY291dC5wcmVjaXNpb24oNyk7CiAgICBpbnQgcXE7IGNpbiA+PiBxcTsKICAgIHEucmVzaXplKHFxKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgcXE7ICsraSkgewogICAgICAgIGNpbiA+PiBxW2ldLnR5cGU7CiAgICAgICAgaWYgKHFbaV0udHlwZSA9PSAxKSB7CiAgICAgICAgICAgIGNpbiA+PiBxW2ldLnRpbWUgPj4gcVtpXS5zcGVlZDsKICAgICAgICAgICAgcG9zLnB1c2hfYmFjayhxW2ldLnRpbWUpOwogICAgICAgIH0KICAgICAgICBpZiAocVtpXS50eXBlID09IDIpIHsKICAgICAgICAgICAgY2luID4+IHFbaV0udGltZTsKICAgICAgICB9CiAgICAgICAgaWYgKHFbaV0udHlwZSA9PSAzKSB7CiAgICAgICAgICAgIGNpbiA+PiBxW2ldLmwgPj4gcVtpXS5yID4+IHFbaV0uc3RhcnQ7CiAgICAgICAgfQogICAgfQogICAgc29ydChwb3MuYmVnaW4oKSwgcG9zLmVuZCgpKTsKICAgIHBvcy5lcmFzZSh1bmlxdWUocG9zLmJlZ2luKCksIHBvcy5lbmQoKSksIHBvcy5lbmQoKSk7CiAgICBpZiAocG9zLnNpemUoKSA9PSAwKSBwb3MucHVzaF9iYWNrKDApOwogICAgbm9kZSogdCA9IG5ldyBub2RlKDAsIHBvcy5zaXplKCktMSk7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IHFxOyArK2kpIHsKICAgICAgICBpZiAocVtpXS50eXBlID09IDEpIHsKICAgICAgICAgICAgaW50IGlkID0gbG93ZXJfYm91bmQocG9zLmJlZ2luKCksIHBvcy5lbmQoKSwgcVtpXS50aW1lKS1wb3MuYmVnaW4oKTsKICAgICAgICAgICAgdC0+dXBkYXRlKGlkLCBxW2ldLnRpbWUsIHFbaV0uc3BlZWQpOwogICAgICAgIH0KICAgICAgICBpZiAocVtpXS50eXBlID09IDIpIHsKICAgICAgICAgICAgaW50IGlkID0gbG93ZXJfYm91bmQocG9zLmJlZ2luKCksIHBvcy5lbmQoKSwgcVtpXS50aW1lKS1wb3MuYmVnaW4oKTsKICAgICAgICAgICAgdC0+ZGVsKGlkKTsKICAgICAgICB9CiAgICAgICAgaWYgKHFbaV0udHlwZSA9PSAzKSB7CiAgICAgICAgICAgIGludCBsID0gbG93ZXJfYm91bmQocG9zLmJlZ2luKCksIHBvcy5lbmQoKSwgcVtpXS5sKS1wb3MuYmVnaW4oKTsKICAgICAgICAgICAgaW50IHIgPSAtLXVwcGVyX2JvdW5kKHBvcy5iZWdpbigpLCBwb3MuZW5kKCksIHFbaV0uciktcG9zLmJlZ2luKCk7CiAgICAgICAgICAgIGlmIChxW2ldLnN0YXJ0ID09IDApCiAgICAgICAgICAgICAgICBjb3V0IDw8IGZpeGVkIDw8IHFbaV0ubCA8PCAnXG4nOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBjb3V0IDw8IGZpeGVkIDw8IHQtPnF1ZXJ5KGwsIHIsIHFbaV0uciwgcVtpXS5zdGFydCkgPDwgJ1xuJzsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQo=