Contest Duration: ~ (local time) (100 minutes) Back to Home

Submission #855735

Source Code Expand

Copy
```#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
int N;
cin >> N;

vector<int> x;
inputVector(x, N);

vector<int> nx(N);
int L, Q;
cin >> L >> Q;

if (N > 1000 || Q > 1000) {
cout << 0 << endl;
return 0;
}

for (int i = 0; i < N; i++) {
int pt = i;
while (pt < N && x[pt] - x[i] <= L) {
pt++;
}
nx[i] = pt - 1;
}

rep(loop, Q) {
int a, b;
cin >> a >> b;
a--; b--;

if (a > b) {
swap(a, b);
}

int ret = 0;
while (a < b) {
a = nx[a];
ret++;
}

cout << ret << endl;
}

return 0;
}
```

#### Submission Info

Submission Time 2016-08-28 21:31:12+0900 E - Tak and Hotels iwashi31 C++14 (GCC 5.4.1) 200 1470 Byte WA 79 ms 1908 KB

#### Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 example_01.txt
Case Name Status Exec Time Memory
example_01.txt 4 ms 256 KB