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

Submission #856583

Source Code Expand

Copy
```#include <cmath>
#include <vector>
#include <iostream>
#include <limits>
#include <iostream>
#include <vector>
#include <cassert>
#include <complex>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long Long;

Long nex[100010][20];

int main(){

int N;
cin >> N;
vector<int> X(N);
for(int &v : X)
cin >> v;
N++;
X.push_back(X.back());
int L;
cin >> L;
// nex 0
for(int i = 0; i < N; ++i){
int nX = X[i]+L;
int p = upper_bound(X.begin(),X.end(),nX) - X.begin();
p--;
nex[i][0] = p;
}
for(int i = 1; i < 20; ++i){
for(int j = 0; j < N; ++j){
nex[j][i] = nex[ nex[j][i-1] ][i-1];
}
}
int Q;
cin >> Q;
for(int i = 0; i < Q; ++i){
int a,b;
cin >> a >> b;
a--;b--;
if(a > b)swap(a,b);
int c = 0;
for(int i = 19; i >= 0; --i){
if(nex[a][i] < b){
c += (1<<i);
a = nex[a][i];
}
}
c++;
cout << c << endl;
}

}

/*

*/

```

#### Submission Info

Submission Time 2016-08-28 22:11:34+0900 E - Tak and Hotels cjtoribio C++14 (GCC 5.4.1) 700 1039 Byte AC 1033 ms 16888 KB

#### Judge Result

Score / Max Score 0 / 0 200 / 200 500 / 500
Status
 AC × 1
 AC × 14
 AC × 27
Set Name Test Cases
Sample example_01.txt
Case Name Status Exec Time Memory
example_01.txt AC 4 ms 256 KB
subtask1_01.txt AC 4 ms 256 KB
subtask1_02.txt AC 4 ms 256 KB
subtask1_03.txt AC 11 ms 384 KB
subtask1_04.txt AC 12 ms 384 KB
subtask1_05.txt AC 11 ms 384 KB
subtask1_06.txt AC 9 ms 384 KB
subtask1_07.txt AC 8 ms 384 KB
subtask1_08.txt AC 13 ms 384 KB
subtask1_09.txt AC 14 ms 384 KB
subtask1_10.txt AC 14 ms 384 KB
subtask1_11.txt AC 13 ms 384 KB
subtask1_12.txt AC 14 ms 384 KB
subtask1_13.txt AC 11 ms 384 KB
subtask2_01.txt AC 935 ms 16760 KB
subtask2_02.txt AC 1026 ms 16760 KB
subtask2_03.txt AC 963 ms 16632 KB
subtask2_04.txt AC 580 ms 10876 KB
subtask2_05.txt AC 554 ms 11004 KB
subtask2_06.txt AC 812 ms 16504 KB
subtask2_07.txt AC 858 ms 16760 KB
subtask2_08.txt AC 1032 ms 16760 KB
subtask2_09.txt AC 924 ms 16760 KB
subtask2_10.txt AC 1033 ms 16760 KB
subtask2_11.txt AC 979 ms 15512 KB
subtask2_12.txt AC 796 ms 16888 KB
subtask2_13.txt AC 798 ms 16504 KB