#include #include #include using namespace std; const int MAXN = 1e5 + 5; const int maxLog = 17; int n; int a[MAXN]; int logValue[MAXN*2]; struct segmentTree { int l, r; int maxValue; segmentTree *L, *R; segmentTree(int l, int r, int value) { this->l = l; this->r = r; this->maxValue = value; this->L = nullptr; this->R = nullptr; } void build(int l, int r, int a[]) { if(l==r) { this->maxValue = a[l]; return; } this->L = new segmentTree(l, (l+r)/2, -1); this->R = new segmentTree((l+r)/2+1, r, -1); this->L->build(l, (l+r)/2, a); this->R->build((l+r)/2+1, r, a); this->maxValue = max(this->L->maxValue, this->R->maxValue); } int query(int ql, int qr) { if(this->l>=ql && r<=qr) return this->maxValue; if(this->rl>qr) return -1; return max(this->L->query(ql, qr), this->R->query(ql, qr)); } }; int sparse[20][MAXN]; int maxTable[20][MAXN]; void makeSparse(int a[]) { for(int i = 0;ibuild(0, n-1, sparse[0]); for(int i = 1;ibuild(0, n-1, sparse[i]); } } int main() { ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); ifstream cin("jumps.in"); ofstream cout("jumps.out"); int Q; int l, r; int current = 0, answer = 0; cin >> n; for(int i = 0;i> a[i]; a[i] += i; } initLog(); precalc(); cin >> Q; while(Q--) { cin >> l >> r; l--; r--; answer = 0; current = l; for(int i = maxLog-1;i>=0;i--) { int x = T[i]->query(l, current); if(x