#include using namespace std; using ll = long long; using P = pair; using T = tuple; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a struct BIT{ int n; vector data; BIT(int n=0) : n(n), data(n+1){} T sum(int i){ T res = 0; for(; i; i -= i&-i){ res += data[i]; } return res; } void add(int i, T x){ for(; i <= n; i += i&-i){ data[i] += x; } } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,q; cin >> n; BIT bit(n), ok(n); vector

a(n), t(n); rep(i,n){ cin >> a[i].first >> t[i].first; t[i].first--; bit.add(i+1, a[i].first); a[i].first += t[i].first; a[i].second = t[i].second = i+1; } sort(all(a)); sort(all(t)); cin >> q; vector ans(q); vector query(q); rep(i,q){ ll d,l,r; cin >> d >> l >> r; l--; query[i] = {d,l,r,i}; } sort(all(query)); int nb = 0, ne = 0; for(auto [d,l,r,i]:query){ while(nb