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

Submission #856123

Source Code Expand

Copy
```#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(j,k) for (int j = 0; j < (int)(k); j++)

int n;
ll x[100010];
ll L;
int Q;
int a[100010], b[100010];

// x[i]から2^i回のジャンプで行けるところ
const int LOG = 33;
ll go[100010][LOG];

int solve(int a, int b) {
if (a >= b) return 0;
if (go[a][0] >= b) return 1;

int i = 0;
while (go[a][i] <= b) {
++i;
}
--i;
return (1 << i) + solve(go[a][i], b);
}

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i];
}
x[n] = 2e9;
cin >> L >> Q;
for (int i = 0; i < n; i++) {
int k = upper_bound(x + i, x + n, x[i] + L) - x;
go[i][0] = min(n - 1, k - 1);
}
for (int i = 0; i < LOG - 1; i++) {
for (int j = 0; j < n; j++) {
go[j][i + 1] = go[go[j][i]][i];
}
}
for (int i = 0; i < Q; i++) {
int a, b;
cin >> a >> b;
--a; --b;
if (a > b) swap(a, b);
//cout << 'a' << endl;
cout << solve(a, b) << endl;
}
}```

#### Submission Info

Submission Time 2016-08-28 21:47:59+0900 E - Tak and Hotels tubo28 C++14 (GCC 5.4.1) 0 1831 Byte TLE 3160 ms 27264 KB

#### Judge Result

Score / Max Score 0 / 0 0 / 200 0 / 500
Status
 AC × 1
 AC × 3 TLE × 11
 AC × 5 TLE × 22
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 TLE 3153 ms 256 KB
subtask1_02.txt AC 4 ms 256 KB
subtask1_03.txt TLE 3153 ms 512 KB
subtask1_04.txt TLE 3157 ms 512 KB
subtask1_05.txt TLE 3153 ms 512 KB
subtask1_06.txt TLE 3153 ms 384 KB
subtask1_07.txt TLE 3153 ms 384 KB
subtask1_08.txt AC 11 ms 512 KB
subtask1_09.txt TLE 3153 ms 512 KB
subtask1_10.txt TLE 3153 ms 512 KB
subtask1_11.txt TLE 3153 ms 512 KB
subtask1_12.txt TLE 3153 ms 512 KB
subtask1_13.txt TLE 3157 ms 512 KB
subtask2_01.txt TLE 3156 ms 26880 KB
subtask2_02.txt TLE 3156 ms 27008 KB
subtask2_03.txt TLE 3156 ms 26880 KB
subtask2_04.txt AC 453 ms 17792 KB
subtask2_05.txt TLE 3159 ms 17664 KB
subtask2_06.txt AC 690 ms 27008 KB
subtask2_07.txt TLE 3156 ms 26880 KB
subtask2_08.txt TLE 3156 ms 26880 KB
subtask2_09.txt TLE 3156 ms 27264 KB
subtask2_10.txt TLE 3156 ms 26880 KB
subtask2_11.txt TLE 3155 ms 24832 KB
subtask2_12.txt TLE 3160 ms 26880 KB
subtask2_13.txt TLE 3156 ms 27008 KB