Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define MAXN 100005
- int n, v[MAXN], L;
- int t[MAXN];
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cin >> n;
- for(int i = 1; i <= n; ++i) {
- cin >> v[i];
- }
- cin >> L;
- t[0] = t[1] = 0;
- for(int i = 2; i <= n; ++i) {
- for(int j = 1; j < i; ++j) {
- if(v[i] - v[j] <= L) {
- t[i] = t[j] + 1;
- break;
- }
- }
- }
- int q, a, b;
- cin >> q;
- while(q--) {
- cin >> a >> b;
- if(a > b) {
- swap(a,b);
- }
- if(t[a] == t[b])
- cout << 1 << endl;
- else
- cout << t[b] - t[a] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement