#include #include #include #include #include using namespace std; using ll = long long; class Rational { public: Rational(ll nn = 0, ll dd = 1) { n = nn; d = dd; Reduction(); } Rational operator+() const { return *this; } Rational& operator=(ll nn) { n = nn; d = 1; return *this; } Rational& operator = (const Rational& r) { n = r.n; d = r.d; return *this; } Rational& operator += (const Rational& r) { n = n * r.d + r.n * d; d *= r.d; Reduction(); return *this; } Rational& operator -= (const Rational& r) { n = n * r.d - r.n * d; d *= r.d; Reduction(); return *this; } Rational& operator *= (const Rational& r) { n *= r.n; d *= r.d; Reduction(); return *this; } Rational& operator /= (const Rational& r) { n *= r.d; d *= r.n; Reduction(); return *this; } bool operator ==(const Rational& r) { return n * r.d == r.n * d; } bool operator !=(const Rational& r) { return !(*this == r); } bool operator <(const Rational& r) { if (d == 0 && r.d == 0) return n < 0 && 0 < r.n; if (r.d == 0) return r.n > 0; if (d == 0) return n < 0; return n * r.d < r.n* d; } bool operator >(const Rational& r) { if (d == 0 && r.d == 0) return r.n < 0 && 0 < n; if (r.d == 0) return r.n < 0; if (d == 0) return n > 0; return n * r.d > r.n* d; } bool operator <=(const Rational& r) { return !(*this > r); } bool operator >=(const Rational& r) { return !(*this < r); } void Reduction() { ll g = gcd(n, d); if (g == 0)return; if (d < 0)g *= -1; n /= g; d /= g; } // d is not negative ll n, d; }; static Rational operator + (const Rational& l, const Rational& r) { return Rational(l) += r; } static Rational operator - (const Rational& l, const Rational& r) { return Rational(l) -= r; } static Rational operator * (const Rational& l, const Rational& r) { return Rational(l) *= r; } static Rational operator / (const Rational& l, const Rational& r) { return Rational(l) /= r; } static bool operator < (const Rational& l, const Rational& r) { return Rational(l) < r; } static bool operator > (const Rational& l, const Rational& r) { return Rational(l) > r; } int main() { ll a, q; cin >> a >> q; set> vxy; set> xyv; ll minf = -3e18; for (ll qs = 0; qs < q; qs++) { ll qq; cin >> qq; if (qq == 1) { ll s, t; cin >> s >> t; ll x = s + t; ll y = -s * t; auto erlast = xyv.lower_bound(make_tuple(x, minf, minf)); ll lx = -1, ly = -1; Rational lv = -1; if (erlast != xyv.end()) { auto [bx, by, bv] = *erlast; if (x * bv + y <= bx * bv + by) { continue; } lx = bx; ly = by; lv = Rational(by - y, x - bx); while (1) { erlast++; if (erlast == xyv.end()) { break; } auto [xx, yy, vv] = *erlast; if (x * vv + y < xx * vv + yy) { break; } if (x * vv + y == xx * vv + yy) { lx = -1; ly = -1; lv = -1; break; } lx = xx; ly = yy; lv = Rational(yy - y, x - xx); } } Rational fv = 0; auto erfirst = xyv.lower_bound(make_tuple(x, minf, minf)); while (1) { if (erfirst == xyv.begin()) { fv = 0; break; } erfirst--; auto [xx, yy, vv] = *erfirst; if (x * vv + y < xx * vv + yy) { fv = Rational(yy - y, x - xx); erfirst++; break; } } for (auto eit = erfirst; eit != erlast; eit++) { auto [ex, ey, ev] = *eit; vxy.erase(make_tuple(ev, ex, ey)); } xyv.erase(erfirst, erlast); xyv.emplace(x, y, fv); vxy.emplace(fv, x, y); if (lv >= 0) { xyv.emplace(lx, ly, lv); vxy.emplace(lv, lx, ly); } } else { ll t; cin >> t; auto it = vxy.lower_bound(make_tuple(Rational(t), minf, minf)); if (it == vxy.begin()) { cout << "0\n"; continue; } it--; auto [vv, xx, yy] = *it; ll ans = -a * t * t + a * xx * t + a * yy; cout << max(ans, 0LL) << "\n"; } } return 0; }