ソースコード 拡げる

Copy
```#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

const int logs = 17;
int skip[17][100000];

int main()
{
int n;
scanf("%d", &n);

vector<int> xs(n);
for (auto &x: xs) scanf("%d", &x);

int l, q;
scanf("%d%d", &l, &q);

// vector<vector<int>> skip(17, vector<int>(n));

for (int j = 0; j < n; j++) {
if (j == n - 1) skip[0][j] = n;
else skip[0][j] = prev(upper_bound(xs.begin(), xs.end(), xs[j] + l)) - xs.begin();
}

for (int i = 1; i < logs; i++) {
for (int j = 0; j < n; j++) {
skip[i][j] = skip[i - 1][j];
if (skip[i][j] < n) skip[i][j] = skip[i - 1][skip[i][j]];
}

}

// for (int i = 0; i < skip.size(); i++) {
//     for (int j = 0; j < n; j++) {
//         cerr << i << ", " << j << ": " << skip[i][j] << endl;
//     }
//     cerr << endl;
// }

//for (auto &q: qs) {
while (q--) {
// vector<pair<int, int>> qs(q);
// for (auto &q: qs) scanf("%d%d", &q.first, &q.second), q.first--, q.second--;
int ans = 0, cur, goal;
scanf("%d%d", &cur, &goal);
cur--, goal--;

if (cur > goal) swap(cur, goal);

int span = logs - 1;

while (cur < goal) {
// cerr << "* " << cur << endl;
// int longest = 0, next = cur;

while (span > 0 && skip[span][cur] > goal) span--;
cur = skip[span][cur];
ans += 1 << span;
}

printf("%d\n", ans);
}

return 0;
}```

#### 提出情報

提出日時 2016-08-28 22:24:58+0900 E - 高橋君とホテル tanakh C++14 (GCC 5.4.1) 700 1732 Byte AC 148 ms 7808 KB

#### コンパイルエラー

```./Main.cpp: In function ‘int main()’:
./Main.cpp:18:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:21:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for (auto &x: xs) scanf("%d", &x);
^
./Main.cpp:24:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &l, &q);
^
./Main.cpp:53:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &cur, &goal);
^
```

#### ジャッジ結果

 AC × 1
 AC × 14
 AC × 27
セット名 テストケース
Sample example_01.txt
ケース名 結果 実行時間 メモリ
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 5 ms 384 KB
subtask1_04.txt AC 5 ms 384 KB
subtask1_05.txt AC 5 ms 384 KB
subtask1_06.txt AC 4 ms 384 KB
subtask1_07.txt AC 4 ms 384 KB
subtask1_08.txt AC 5 ms 384 KB
subtask1_09.txt AC 5 ms 384 KB
subtask1_10.txt AC 5 ms 384 KB
subtask1_11.txt AC 5 ms 384 KB
subtask1_12.txt AC 5 ms 384 KB
subtask1_13.txt AC 5 ms 384 KB
subtask2_01.txt AC 137 ms 7680 KB
subtask2_02.txt AC 148 ms 7808 KB
subtask2_03.txt AC 134 ms 7680 KB
subtask2_04.txt AC 68 ms 4992 KB
subtask2_05.txt AC 90 ms 5248 KB
subtask2_06.txt AC 104 ms 7424 KB
subtask2_07.txt AC 139 ms 7680 KB
subtask2_08.txt AC 144 ms 7808 KB
subtask2_09.txt AC 144 ms 7808 KB
subtask2_10.txt AC 146 ms 7808 KB
subtask2_11.txt AC 140 ms 7296 KB
subtask2_12.txt AC 94 ms 7808 KB
subtask2_13.txt AC 105 ms 7424 KB