Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"


template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef cc_hash_table<int, int, hash<int > > ht;


#define int long long 
#define  st first
#define  nd second

const int M = 1e8;
const int  maxn = 1e5+5;
const int  inf =  1e16;

// 1 base indexing build(1,1,n);
struct data
{
	//Use required attributes 
	//Default Values
	int  lo ; 
	int  lazy_inc;
	int  lazy_ass;
	data() {
	  lazy_inc = lazy_ass=0;
	  lo = inf;
	}
};

#define lnode 2*node
#define rnode 2*node + 1

struct SegTree
{
	int N;
	vector<data> st;

	void init(int n)
	{
		N = n;
		st.resize(4 * N + 5);
	}

	//Write reqd merge functions
	void merge1(data &cur, data &l, data &r)
	{
        cur.lo = min(l.lo , r.lo);
	}

	//Handle lazy propagation appriopriately
	void propagate(int node, int L, int R)
	{
		if(L != R)
		{
			st[lnode].lazy_ass   +=   st[node].lazy_ass;
			st[rnode].lazy_ass   +=   st[node].lazy_ass;
			st[lnode].lazy_inc   +=   st[node].lazy_inc;
			st[rnode].lazy_inc   +=   st[node].lazy_inc;
		}
        if(st[node].lazy_ass){
            st[node].lo =  st[node].lazy_ass + L +1 ;
            st[node].lazy_ass=0;
		}
		if(st[node].lazy_inc){
			st[node].lo +=1;
            st[node].lazy_inc=0;
		}
	}
 
	void build(int node, int L, int R)
	{
		if(L==R)
		{
			st[node].lo= L-1;
			return;
		}
		int M=(L + R)/2;
		build(lnode, L, M);
		build(rnode, M + 1, R);
		merge1(st[node], st[lnode], st[rnode]);
	}

	data Query(int node, int L, int R, int i, int j)
	{
		propagate(node, L, R);
		if(j<L || i>R){
			return data();
		}
		if(i<=L && R<=j)
			return st[node];
		int M = (L + R)/2;
		data left = Query(lnode, L, M, i, j);
		data right= Query(rnode, M + 1, R, i, j);
		data cur;
		merge1(cur, left, right);
		return cur;
	}

	data pQuery(int node, int L, int R, int pos)
	{
		return Query(node,L,R,pos,pos);
	}

	void Update(int node, int L, int R, int i, int j, int val) /// assignment of L-i
	{

		propagate(node, L, R);
		if(j<L || i>R)
			return;
		if(i<=L && R<=j)
		{
			st[node].lazy_ass = val;
			propagate(node, L, R);
			return;
		}
		int M = (L + R)/2;
		Update(lnode, L, M, i, j, val);
		Update(rnode, M + 1, R, i, j, val);
		merge1(st[node], st[lnode], st[rnode]);
	}
    void Update2(int node, int L,int R,int i , int j){
        propagate(node, L, R);
		if(j<L || i>R)
			return;
		if(i<=L && R<=j)
		{
			st[node].lazy_inc = 1;
			propagate(node, L, R);
			return;
		}
		int M = (L + R)/2;
		Update2(lnode, L, M, i, j);
		Update2(rnode, M + 1, R, i, j);
		merge1(st[node], st[lnode], st[rnode]);
	}
	void pUpdate(int node, int L, int R, int pos, int val)
	{
		Update(node,L,R,pos,pos,val);
	}

	data query(int pos)
	{
		return pQuery(1, 1, N, pos);
	}

	data query(int l, int r)
	{
		return Query(1, 1, N, l, r);
	}

	void update(int pos, int val)
	{
		pUpdate(1, 1, N, pos, val);
	}

	void update(int l, int r, int val)
	{
		Update(1, 1, N, l, r, val);
	}
	void update2(int l ,int r)
	{
		Update2(1,1,N,l,r);
	}
};

int32_t main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int h , w ; 
  cin >> h >> w ;
  SegTree t;
  t.init(w);
  t.build(1,1,w);
  for(int i = 0 ; i < h ; i++){
     int l , r ; 
	 cin >> l >> r ; 
	 if(l==1 and r==w){
		 t.update(l,r,inf);
	 }
	 else if(l==1){
		 t.update(l,r,inf);
		 t.update2(r+1,w);
	 }
	 else{
	 
	 t.update2(1,l-1);
	 if(r!=w){
		 t.update2(r+1,w);
	 }	 
	 int n = (t.query(l-1)).lo;
     t.update(l,r,n-l);
	 
	 
	 }
	 int ans = t.query(1,w).lo;
	 if(ans<inf){
		 cout << ans ;
	 }
	 else{
		 cout << -1;
	 }
	 cout << "\n";
  }    
  
}



Compiler output:
a.cc:54:20: error: template argument 1 is invalid
   54 |         vector<data> st;
      |                    ^
a.cc:54:20: error: template argument 2 is invalid
a.cc:63:21: error: reference to 'data' is ambiguous
   63 |         void merge1(data &cur, data &l, data &r)
      |                     ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:63:21: error: 'data' has not been declared
   63 |         void merge1(data &cur, data &l, data &r)
      |                     ^~~~
a.cc:63:32: error: reference to 'data' is ambiguous
   63 |         void merge1(data &cur, data &l, data &r)
      |                                ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:63:32: error: 'data' has not been declared
   63 |         void merge1(data &cur, data &l, data &r)
      |                                ^~~~
a.cc:63:41: error: reference to 'data' is ambiguous
   63 |         void merge1(data &cur, data &l, data &r)
      |                                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:63:41: error: 'data' has not been declared
   63 |         void merge1(data &cur, data &l, data &r)
      |                                         ^~~~
a.cc:101:9: error: reference to 'data' is ambiguous
  101 |         data Query(int node, int L, int R, int i, int j)
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:117:9: error: reference to 'data' is ambiguous
  117 |         data pQuery(int node, int L, int R, int pos)
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:159:9: error: reference to 'data' is ambiguous
  159 |         data query(int pos)
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc:164:9: error: reference to 'data' is ambiguous
  164 |         data query(int l, int r)
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:35:8: note:                 'struct data'
   35 | struct data
      |        ^~~~
a.cc: In member function 'void SegTree::init(long long int)':
a.cc:59:20: error: request for member 'resize' in '((SegTree*)this)->SegTree::first', which is of non-class type 'int'
   59 |                 st.resize(4 * N + 5);
      |                    ^~~~~~
a.cc: In member function 'void SegTree::merge1(int&, int&, int&)':
a.cc:65:13: error: request for member 'lo' in 'cur', which is of non-class type 'int'
   65 |         cur.lo = min(l.lo , r.lo);
      |             ^~
a.cc:65:24: error: request for member 'lo' in 'l', which is of non-class type 'int'
   65 |         cur.lo = min(l.lo , r.lo);
      |                        ^~
a.cc:65:31: error: request for member 'lo' in 'r', which is of non-class type 'int'
   65 |         cur.lo = min(l.lo , r.lo);
      |                               ^~
a.cc: In member function 'void SegTree::propagate(long long int, long long int, long long int)':
a.cc:73:27: error: invalid types 'int[long long int]' for array subscript
   73 |                         st[lnode].lazy_ass   +=   st[node].lazy_ass;
      |                           ^
a.cc:73:53: error: invalid types 'int[long long int]' for array subscript
   73 |                         st[lnode].lazy_ass   +=   st[node].lazy_ass;
      |                                                     ^
a.cc:74:27: error: inva