#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int query(vector &platforms, int i, int j) { int moves = 0; while (i + platforms[i] < j) { moves++; int maxi = -1; int idx = -1; for (int k = i + 1; k <= i + platforms[i]; k++) { if (platforms[k] + k > maxi) { maxi = platforms[k] + k; idx = k; } } i = idx; } return 1 + moves; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); ifstream myfile("jumps.in"); ofstream myfile2; myfile2.open("jumps.out"); int n; vector platforms; if (myfile.is_open()) { myfile >> n; for (int i = 0; i < n; i++) { int t; myfile >> t; platforms.push_back(t); } int q; myfile >> q; while (q--) { int i, j; myfile >> i >> j; int ans = query(platforms, i - 1, j - 1); myfile2 << ans << "\n"; } myfile.close(); } myfile2.close(); exit(0); }