Submission #856300
Source Code Expand
Copy
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
vector<tuple<int, int, int>> s[2][100000];
int N;
int x[100000];
int L, Q;
int ans[100000];
int dist[100000];
int bs;
void solve(int dir) {
rep(i, N - 1) {
int nxt = upper_bound(x, x + N, x[i] + L) - 1 - x;
if (s[dir][i].size() < bs) {
for (const auto &t : s[dir][i]) {
int b, j, cost;
tie(b, j, cost) = t;
if (nxt >= b) {
ans[j] = cost + 1;
}
else {
s[dir][nxt].emplace_back(b, j, cost + 1);
}
}
}
else {
int c = 1, d = 0;
dist[i] = 0;
for (int j = i + 1; j < N; j++) {
d += x[j] - x[j - 1];
if (d > L) {
d = x[j] - x[j - 1];
c++;
}
dist[j] = c;
}
for (const auto &t : s[dir][i]) {
int b, j, cost;
tie(b, j, cost) = t;
ans[j] = cost + dist[b];
}
}
s[dir][i].~vector<tuple<int, int, int>>();
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
rep(i, N)cin >> x[i];
cin >> L >> Q;
bs = sqrt(Q);
rep(i, Q) {
int a, b;
cin >> a >> b;
a--; b--;
if (a < b) {
s[0][a].emplace_back(b, i, 0);
}
else {
a = N - a - 1;
b = N - b - 1;
s[1][a].emplace_back(b, i, 0);
}
}
solve(0);
reverse(x, x + N);
rep(i, N)x[i] *= -1;
solve(1);
rep(i, Q)cout << ans[i] << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Tak and Hotels |
User |
hirokazu1020 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1879 Byte |
Status |
RE |
Exec Time |
1575 ms |
Memory |
9524 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
All |
Score / Max Score |
0 / 0 |
0 / 200 |
0 / 500 |
Status |
|
|
|
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 |
RE |
200 ms |
4992 KB |
subtask1_01.txt |
RE |
195 ms |
4992 KB |
subtask1_02.txt |
RE |
193 ms |
4992 KB |
subtask1_03.txt |
RE |
201 ms |
4992 KB |
subtask1_04.txt |
RE |
208 ms |
4992 KB |
subtask1_05.txt |
RE |
207 ms |
4992 KB |
subtask1_06.txt |
RE |
205 ms |
4992 KB |
subtask1_07.txt |
RE |
203 ms |
4992 KB |
subtask1_08.txt |
RE |
207 ms |
4992 KB |
subtask1_09.txt |
RE |
200 ms |
4992 KB |
subtask1_10.txt |
RE |
201 ms |
4992 KB |
subtask1_11.txt |
RE |
206 ms |
4992 KB |
subtask1_12.txt |
RE |
205 ms |
4992 KB |
subtask1_13.txt |
RE |
208 ms |
4992 KB |
subtask2_01.txt |
RE |
1536 ms |
9032 KB |
subtask2_02.txt |
RE |
1421 ms |
8576 KB |
subtask2_03.txt |
RE |
1575 ms |
8996 KB |
subtask2_04.txt |
RE |
714 ms |
7168 KB |
subtask2_05.txt |
RE |
773 ms |
7680 KB |
subtask2_06.txt |
RE |
840 ms |
8448 KB |
subtask2_07.txt |
RE |
1031 ms |
9088 KB |
subtask2_08.txt |
RE |
1379 ms |
8576 KB |
subtask2_09.txt |
RE |
1380 ms |
8576 KB |
subtask2_10.txt |
RE |
1354 ms |
9088 KB |
subtask2_11.txt |
RE |
1317 ms |
8448 KB |
subtask2_12.txt |
RE |
988 ms |
9524 KB |
subtask2_13.txt |
RE |
845 ms |
9048 KB |