#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct IOST { IOST() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); } } IOST; // template atcoder segtree using S = ll; S op(S a, S b) { return min(a, b); } S e() { return 1e18; } using segtree = atcoder::segtree; void solve() { int n, q; cin >> n >> q; segtree addseg(n), decseg(n); rep(i, 0, n) addseg.set(i, i * 2); rep(i, 0, n) decseg.set(i, 0); rep(lp, 0, q) { int t; cin >> t; if (t == 1) { int x; cin >> x; x--; ll mn = min(addseg.prod(x, n) - x, decseg.prod(0, x) + x); cout << mn << "\n"; } else { int x, c; cin >> x >> c; x--; ll mn = min({addseg.prod(x, n) - x, decseg.prod(0, x) + x, (ll)c}); addseg.set(x, mn + x); decseg.set(x, mn - x); } } } int main() { int t = 1; // cin >> t; rep(i, 0, t) solve(); }