Submission #856579


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) {
    int ans = 0;
    while (1) {
        if (go[a][0] >= b) return ans + 1;
        int i = 0;
        while (go[a][i] < b) ++i;
        --i;
        ans += 1 << i;
        a = go[a][i];
        // cout << a << ' ' << b << endl;
    }
}

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

    while (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 << 'a' << endl;
            cout << solve(a, b) << endl;
        }
    }
}

Submission Info

Submission Time
Task E - Tak and Hotels
User tubo28
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1986 Byte
Status AC
Exec Time 952 ms
Memory 27392 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 500 / 500
Status
AC × 1
AC × 14
AC × 27
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 AC 5 ms 256 KB
subtask1_02.txt AC 4 ms 256 KB
subtask1_03.txt AC 12 ms 512 KB
subtask1_04.txt AC 13 ms 512 KB
subtask1_05.txt AC 12 ms 512 KB
subtask1_06.txt AC 9 ms 384 KB
subtask1_07.txt AC 9 ms 384 KB
subtask1_08.txt AC 13 ms 512 KB
subtask1_09.txt AC 13 ms 512 KB
subtask1_10.txt AC 13 ms 512 KB
subtask1_11.txt AC 13 ms 512 KB
subtask1_12.txt AC 13 ms 512 KB
subtask1_13.txt AC 12 ms 512 KB
subtask2_01.txt AC 952 ms 27264 KB
subtask2_02.txt AC 943 ms 27392 KB
subtask2_03.txt AC 940 ms 27136 KB
subtask2_04.txt AC 557 ms 17792 KB
subtask2_05.txt AC 586 ms 17920 KB
subtask2_06.txt AC 851 ms 27008 KB
subtask2_07.txt AC 897 ms 27264 KB
subtask2_08.txt AC 916 ms 27392 KB
subtask2_09.txt AC 906 ms 27392 KB
subtask2_10.txt AC 935 ms 27392 KB
subtask2_11.txt AC 902 ms 25216 KB
subtask2_12.txt AC 855 ms 27392 KB
subtask2_13.txt AC 848 ms 27008 KB