#include using namespace std; template class segtree{ Tp *tree; Tp (*operation)(const Tp&, const Tp&); Tp ident; size_t len, depth; public: segtree(size_t n, Tp (*op)(const Tp&, const Tp&), Tp id) : operation(op), ident(id){ for(depth=1;(1ULL<>1;p>0;p>>=1){ tree[p] = operation(tree[2*p], tree[2*p+1]); } } void add(size_t pos, Tp val){ tree[len+pos] += val; for(size_t p=(len+pos)>>1;p>0;p>>=1){ tree[p] = operation(tree[2*p], tree[2*p+1]); } } Tp queue(size_t left, size_t right){ Tp lval = ident, rval = ident; left += len; right += len; while(true){ if(left >= right) return operation(lval, rval); if(right - left == 1) return operation(lval, operation(tree[left], rval)); if(left & 1) lval = operation(lval, tree[left++]); left >>= 1; if(right & 1) rval = operation(tree[right-1], rval); right >>= 1; } } Tp &operator[](size_t pos){ return tree[len+pos]; } void refresh(){ for(size_t p=len-1;p>0;--p){ tree[p] = operation(tree[2*p], tree[2*p+1]); } } }; int main(){ int N, Q; int a, t, l, r; scanf("%d%d", &N, &Q); segtree> st(N, [](auto x, auto y){ return min(x, y); }, {N+1, -1}); for(int i=0;i