Submission #855874


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;
    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] = 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 << solve(a, b) << endl;
    }
}

Submission Info

Submission Time
Task E - Tak and Hotels
User tubo28
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1751 Byte
Status TLE
Exec Time 3159 ms
Memory 27264 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 500
Status
AC × 1
AC × 1
TLE × 13
AC × 1
TLE × 26
Set Name Test Cases
Sample example_01.txt
Subtask1 example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt
All example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.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 TLE 3153 ms 256 KB
subtask1_03.txt TLE 3157 ms 512 KB
subtask1_04.txt TLE 3153 ms 512 KB
subtask1_05.txt TLE 3157 ms 512 KB
subtask1_06.txt TLE 3153 ms 384 KB
subtask1_07.txt TLE 3153 ms 384 KB
subtask1_08.txt TLE 3153 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 3153 ms 512 KB
subtask2_01.txt TLE 3159 ms 26880 KB
subtask2_02.txt TLE 3159 ms 27008 KB
subtask2_03.txt TLE 3156 ms 26880 KB
subtask2_04.txt TLE 3155 ms 17664 KB
subtask2_05.txt TLE 3155 ms 17664 KB
subtask2_06.txt TLE 3159 ms 26880 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 3157 ms 26880 KB
subtask2_11.txt TLE 3155 ms 24832 KB
subtask2_12.txt TLE 3156 ms 26880 KB
subtask2_13.txt TLE 3156 ms 26880 KB