#include using namespace std; template bool chmin(T& a, T b) { return a > b ? a = b, true : false; } template bool chmax(T& a, T b) { return a < b ? a = b, true : false; } template concept Iterable = requires(T t) { std::begin(t); std::end(t); }; template requires Iterable && (!is_same_v) ostream& operator<<(ostream& os, const T& container) { for (auto& element : container) os << element << ' '; return os; } template requires ranges::range && (!is_same_v, string>) && (!is_same_v, const char*>) ostream& operator<<(ostream& os, R&& range) { for (auto& element : range)os << element << ' '; return os; } template requires Iterable && (!is_same_v) istream& operator>>(std::istream& is, T& container) { for (auto& e : container)is >> e; return is; } using ll = long long; using ull = unsigned long long; using uint = unsigned int; template struct Edge { int to; T weight; bool operator==(Edge e) { return this->to == e.to and this->weight == e.weight; } bool operator<(Edge e) { return this->to == e.to ? this->weight < e.weight : this->to < e.to; } }; #ifdef _DEBUG #define SHOW(n) {const auto& _ret = n; cerr << #n << ": " << _ret << endl;} #define MSG(x) cerr << x << endl; #else #define SHOW(n) #define MSG(x) #endif //AtCoder Library #include using namespace atcoder; //using mint = modint998244353; using mint = modint1000000007; //using mint1 = dynamic_modint<0>; //using mint = modint; //mint::set_mod(); istream& operator>>(istream& is, mint& x) { ll r; is >> r; x = r; return is; } ostream& operator<<(ostream& os, mint& x) { os << x.val(); return os; } //boost //#include //using namespace boost::multiprecision; //using l3 = int128_t; //LONG_MAX -> LLONG_MAX? template struct DynamicLiChaoTree { struct Line { T a, b; Line(T a, T b) : a(a), b(b) {} inline T get(T x)const { return a * x + b; } }; struct Node { Line x; Node* l, * r; Node(const Line& x) : x{ x }, l{ nullptr }, r{ nullptr } {} }; Node* root; DynamicLiChaoTree() : root { nullptr }{} Node* add_line(Node* t, Line& x, const T& l, const T& r, const T& x_l, const T& x_r) { if (not t)return new Node(x); T t_l = t->x.get(l), t_r = t->x.get(r); if (t_l <= x_l and t_r <= x_r)return t; if (t_l >= x_l and t_r >= x_r) { t->x = x; return t; } else { T m = (l + r) / 2; if (m == r)--m; T t_m = t->x.get(m), x_m = x.get(m); if (t_m > x_m) { swap(t->x, x); if (x_l >= t_l) t->l = add_line(t->l, x, l, m, t_l, t_m); else t->r = add_line(t->r, x, m + 1, r, t_m + x.a, t_r); } else { if (t_l >= x_l)t->l = add_line(t->l, x, l, m, x_l, x_m); else t->r = add_line(t->r, x, m + 1, r, x_m + x.a, x_r); } return t; } } void add_line(const T& a, const T& b) { Line x(a, b); root = add_line(root, x, x_low, x_high, x.get(x_low), x.get(x_high)); } Node* add_segment(Node* t, Line& x, const T& a, const T& b, const T& l, const T& r, const T& x_l, const T& x_r) { if (r < a or b < l)return t; if (a <= l and r <= b) { Line y{ x }; return add_line(t, y, l, r, x_l, x_r); } if (t) { T t_l = t->x.get(l), t_r = x.get(r); if (t_l <= x_l and t_r <= x_r)return t; } else { t = new Node(Line(0, id)); } T m = (l + r) / 2; if (m == r)--m; T x_m = x.get(m); t->l = add_segment(t->l, x, a, b, l, m, x_l, x_m); t->r = add_segment(t->r, x, a, b, m + 1, r, x_m + x.a, x_r); return t; } void add_segment(const T& l, const T& r, const T& a, const T& b) { Line x(a, b); root = add_segment(root, x, l, r - 1, x_low, x_high, x.get(x_low), x.get(x_high)); } T query(const Node* t, const T& l, const T& r, const T& x)const { if (not t)return id; if (l == r)return t->x.get(x); T m = (l + r) / 2; if (m == r)--m; if (x <= m)return min(t->x.get(x), query(t->l, l, m, x)); return min(t->x.get(x), query(t->r, m + 1, r, x)); } T query(const T& x)const { return query(root, x_low, x_high, x); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, q; cin >> n >> q; DynamicLiChaoTree t; t.add_segment(1, n + 1, 1, -1); cout << t.query(1) << endl; cout << t.query(n) << endl; while (q--) { int tt; cin >> tt; if (tt == 1) { int x; cin >> x; ll res = t.query(x); cout << res << endl; } else { ll x, c; cin >> x >> c; t.add_segment(1, x, -1, x + c); t.add_segment(x, n + 1, 1, -x + c); } } return 0; }