This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 200000;
int N, Q;
struct S{
	int h, a, b;
};
vector<S> v;
vector<pair<pii, int> > query;
vector<pii> vt;
bool chk[MAX_N+1];
int ans[MAX_N+1];
struct SEG{
	struct NODE{
		int l, r;
		int mx, mn, lmx, lmn, data;
		bool lazy;
	};
	vector<NODE> seg;
	int SZ;
	void add(){
		seg.pb({-1, -1, 0, INF, 0, INF, -1, 0});
	}
	void Init(int x){
		SZ = x;
		add();
		init(0, 0, SZ-1);
	}
	void init(int idx, int s, int e){
		if(s==e)	return;
		seg[idx].l = seg.size(); add();
		seg[idx].r = seg.size(); add();
		init(seg[idx].l, s, (s+e)/2); init(seg[idx].r, (s+e)/2+1, e);
	}
	void Calc(int idx){
		if(seg[idx].l==-1){
			seg[idx].lazy = false;
			seg[idx].lmn = INF; seg[idx].lmx = 0;
			return;
		}
		seg[seg[idx].l].lazy = true;
		seg[seg[idx].l].lmx = max(seg[seg[idx].l].lmx, seg[idx].lmx); seg[seg[idx].l].lmn = min(seg[seg[idx].l].lmn, seg[idx].lmn);
		seg[seg[idx].l].data = max(seg[seg[idx].l].data, seg[seg[idx].l].lmx - seg[seg[idx].l].mn);
		seg[seg[idx].l].data = max(seg[seg[idx].l].data, seg[seg[idx].l].mx - seg[seg[idx].l].lmn);
		seg[seg[idx].r].lazy = true;
		seg[seg[idx].r].lmx = max(seg[seg[idx].r].lmx, seg[idx].lmx); seg[seg[idx].r].lmn = min(seg[seg[idx].r].lmn, seg[idx].lmn);
		seg[seg[idx].r].data = max(seg[seg[idx].r].data, seg[seg[idx].r].lmx - seg[seg[idx].r].mn);
		seg[seg[idx].r].data = max(seg[seg[idx].r].data, seg[seg[idx].r].mx - seg[seg[idx].r].lmn);
		seg[idx].lazy = false;
		seg[idx].lmn = INF; seg[idx].lmx = 0;
	}
	void Update(int x, int y){
		update(0, 0, SZ-1, x, y);
	}
	void update(int idx, int s, int e, int x, int y){
		if(seg[idx].lazy)	Calc(idx);
		if(s==e){
			if(y==-1){
				seg[idx].mx = 0; seg[idx].mn = INF;
				return;
			}else{
				seg[idx].mx = seg[idx].mn = y;
				return;
			}
		}
		if(x<=(s+e)/2){
			update(seg[idx].l, s, (s+e)/2, x, y);
		}else{
			update(seg[idx].r, (s+e)/2+1, e, x, y);
		}
		seg[idx].mx = max(seg[seg[idx].l].mx, seg[seg[idx].r].mx);
		seg[idx].mn = min(seg[seg[idx].l].mn, seg[seg[idx].r].mn);
	}
	void Lazy(int x, int y, int z){
		lazy(0, 0, SZ-1, x, y, z);
	}
	void lazy(int idx, int s, int e, int x, int y, int z){
		if(seg[idx].lazy)	Calc(idx);
		if(x<=s && e<=y){
			seg[idx].lazy = true;
			seg[idx].lmn = z; seg[idx].lmx = z;
			seg[idx].data = max(seg[idx].data, seg[idx].mx - seg[idx].lmn);
			seg[idx].data = max(seg[idx].data, seg[idx].lmx - seg[idx].mn);
			//cout<<"*"<<s<<" "<<e<<" "<<seg[idx].data<<endl;
			return;
		}
		if(x>e || y<s)	return;
		lazy(seg[idx].l, s, (s+e)/2, x, y, z);
		lazy(seg[idx].r, (s+e)/2+1, e, x, y, z);
		seg[idx].data = max(seg[seg[idx].l].data, seg[seg[idx].r].data);
	}
	int Max(int x, int y){
		return calc_max(0, 0, SZ-1, x, y);
	}
	int calc_max(int idx, int s, int e, int x, int y){
		if(seg[idx].lazy)	Calc(idx);
		if(x<=s && e<=y)	{
			//cout<<"&"<<s<<" "<<e<<" "<<seg[idx].data<<endl;
			return seg[idx].data;
		}
		if(x>e || s>y)	return -1;
		return max(calc_max(seg[idx].l, s, (s+e)/2, x, y), calc_max(seg[idx].r, (s+e)/2+1, e, x, y));
	}
};
SEG Seg;
int main(){
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		v.pb({a, b, c});
		vt.pb({i+b, i}); vt.pb({i+c+1, i});
	}
	sort(vt.begin(), vt.end());
	scanf("%d", &Q);
	for(int i=1; i<=Q; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		query.pb({{b-1, a-1}, i});
	}
	Seg.Init(N);
	sort(query.begin(), query.end());
	int idx1 = 0, idx2 = 0;
	for(int i=0; i<N; i++){
		while(idx1<vt.size() && vt[idx1].first==i){
			if(chk[vt[idx1].second]){
				chk[vt[idx1].second] = false;
				//cout<<"OUT "<<vt[idx1].second<<endl;
				Seg.Update(vt[idx1].second, -1);
			}else{
				chk[vt[idx1].second] = true;
				//cout<<"IN "<<vt[idx1].second<<" "<<v[vt[idx1].second].h<<endl;
				Seg.Update(vt[idx1].second, v[vt[idx1].second].h);
			}
			idx1++;
		}
		S now = v[i];
		Seg.Lazy(i-now.b, i - now.a, now.h);
		while(idx2<query.size() && query[idx2].first.first==i){
			ans[query[idx2].second] = Seg.Max(query[idx2].first.second, query[idx2].first.first);
			//cout<<"ANSWER "<<query[idx2].second<<" "<<ans[query[idx2].second]<<endl;
			//cout<<query[idx2].first.second<<" "<<query[idx2].first.first<<endl;
			idx2++;
		}
		//cout<<"END"<<endl;
	}
	for(int i=1; i<=Q; i++){
		printf("%d\n", ans[i]);
	}
	return 0;
}
Compilation message (stderr)
antennas.cpp: In function 'int main()':
antennas.cpp:151:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(idx1<vt.size() && vt[idx1].first==i){
         ~~~~^~~~~~~~~~
antennas.cpp:166:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(idx2<query.size() && query[idx2].first.first==i){
         ~~~~^~~~~~~~~~~~~
antennas.cpp:133:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
antennas.cpp:136:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:141:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
antennas.cpp:144:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |