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

Submission #858865

Source Code Expand

Copy
```#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
if(p) cout << fixed << setprecision(p)  << a << "\n";
else cout << a << "\n";
}
// end of template

int main() {
cin.tie(0);
ios::sync_with_stdio(0);
// source code
int N;
cin >> N;
vector<ll> X(N);
rep(i, N) cin >> X[i];
ll L;
cin >> L;
vector<int> B(N);
rep(i, N){
int l = i + 1, r = N;
while(r - l > 1){
int mid = (l + r) / 2;
if(X[mid] - X[i] <= L) l = mid;
else r = mid;
}
B[i] = l;
}

// doubling
int n = N;
int logN = 1;
while(n > 0) {
n >>= 1;
logN++;
}
vector<vector<int>> D(logN, vector<int>(N));
D[0] = B;

repd(i, 1, logN){
rep(j, N){
if (D[i - 1][j] == N) D[i][j] = N;
else D[i][j] = D[i - 1][D[i - 1][j]];
}
}

int Q;
cin >> Q;
vector<pair<int, int>> A(Q);
rep(i, Q){
int a, b;
cin >> a >> b;
if(a > b) swap(a, b);
a--, b--;

int ret = 1;
for(int j = logN - 1; j >= 0; j--){
if(D[j][a] < b){
ret += 1 << j;
a = D[j][a];
}
}
output(ret, 0);
}

return 0;
}```

Submission Info

Submission Time 2016-08-29 17:08:10+0900 E - Tak and Hotels ctyl C++14 (GCC 5.4.1) 700 1894 Byte AC 166 ms 9848 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 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 6 ms 384 KB
subtask1_06.txt AC 5 ms 256 KB
subtask1_07.txt AC 5 ms 256 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 141 ms 9720 KB
subtask2_02.txt AC 166 ms 9848 KB
subtask2_03.txt AC 141 ms 9592 KB
subtask2_04.txt AC 75 ms 6396 KB
subtask2_05.txt AC 93 ms 6524 KB
subtask2_06.txt AC 117 ms 9464 KB
subtask2_07.txt AC 149 ms 9720 KB
subtask2_08.txt AC 157 ms 9848 KB
subtask2_09.txt AC 160 ms 9848 KB
subtask2_10.txt AC 155 ms 9848 KB
subtask2_11.txt AC 149 ms 9112 KB
subtask2_12.txt AC 100 ms 9848 KB
subtask2_13.txt AC 115 ms 9464 KB