Language: C++

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define nl "\n"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;
#define mt make_tuple
#define vec vector

#define int long long

const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;

typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

struct Node {
	int sum, A, D;
	Node() {
		sum = A = D = 0;
	}
	void reset() {
		A = D = 0;
	}
};

const int N = 2e5 + 5 ;
Node tree[4*N];
int h, w;

void prop(int node,int start, int end) {
	int mid = (start + end) / 2; 

	if(tree[node].A) {
		tree[node].sum = tree[node].A ;
		
		if(start != end) {
			tree[2*node].A = tree[node].A;
			tree[2*node+1].A = tree[node].A + (mid+1-start) * tree[node].D ; 
			tree[2*node].D = tree[node].D;
			tree[2*node+1].D = tree[node].D ; 
		}

		tree[node].reset() ;
	}
}

void update(int l, int r, int node=1, int start = 1, int end = w) {

	prop(node,start,end) ;

	if(start > end or start > r or end < l) return ; 
	int mid = (start + end) / 2; 
	
	if(start >= l and end <= r ) {

		tree[node].sum = (start-l+1) ;
		if(start != end ) {
			tree[2*node].A = (start-l+1);
			tree[2*node].D = 1 ; 
			tree[2*node+1].A = (start-l+1) + (mid+1-start); 
			tree[2*node+1].D = 1 ; 
		}
		return ; 
	}

	update(l,r,2*node,start,mid);
	update(l,r,2*node+1,mid+1,end) ;

	tree[node].sum = min(tree[2*node].sum, tree[2*node+1].sum );
}

int query(int l,int r,int node=1,int start=1, int end=w) {

	prop(node,start,end) ;

	if(start > end or start > r or end < l) return INF ;

	if(start >= l and end <= r ) return tree[node].sum ;

	int mid = (start + end)/2 ;
	return min(query(l,r,2*node,start,mid),query(l,r,2*node+1,mid+1,end)); 
}

void solve() {

	cin >> h >> w; 
	int ep =0 ; 
	int c = 0 ;  
	rep(i,0,n) {
		int a,b; cin >> a >> b;
		if(a <= ep + 1) ep = max(b,ep) ; 
		else update(a,b) ;
		++c;
		if(ep + 1> w) {
			cout << -1 << nl ;
		}
		else {
			int x = query(ep+1,w) ; 
			// error(ep+1,x)
			if(x >= INF) cout << -1 << nl ;
			else cout << x + c<< nl ;
		}
	}
}

int32_t main() {

#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif

    fast;

	// int t; cin >> t; while(t--)
		solve() ;

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:120:17: error: 'n' was not declared in this scope
  120 |         rep(i,0,n) {
      |                 ^
a.cc:15:42: note: in definition of macro 'rep'
   15 | #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
      |                                          ^~~