Submission #863314


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())




int ans[100000];


vector<pair<int,int>> query[100000];
vector<int> child[100000];
vector<int> par;


int N;
int x[100000];
int L, Q;

void dfs(int u) {
	for (auto p : query[u]) {
		ans[p.second] = lower_bound(par.rbegin(),par.rend(), p.first) - par.rbegin() + 1;
	}

	par.push_back(u);
	for (int v : child[u]) {
		dfs(v);
	}
	par.pop_back();
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	rep(i, N)cin >> x[i];
	cin >> L >> Q;
	rep(i, Q) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (a > b) {
			a = N - a - 1;
			b = N - b - 1;
		}
		query[a].emplace_back(b, i);
	}
	rep(i,N-1) {
		if (query[i].empty() && child[i].empty())continue;
		int nxt = upper_bound(x, x + N, x[i] + L) - 1 - x;
		child[nxt].push_back(i);
	}
	dfs(N - 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 1419 Byte
Status WA
Exec Time 887 ms
Memory 18168 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 500
Status
AC × 1
AC × 8
WA × 6
AC × 15
WA × 12
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 11 ms 4992 KB
subtask1_01.txt WA 12 ms 4992 KB
subtask1_02.txt AC 12 ms 4992 KB
subtask1_03.txt AC 20 ms 4992 KB
subtask1_04.txt AC 20 ms 5120 KB
subtask1_05.txt AC 17 ms 4992 KB
subtask1_06.txt AC 16 ms 4992 KB
subtask1_07.txt AC 16 ms 4992 KB
subtask1_08.txt AC 20 ms 4992 KB
subtask1_09.txt WA 20 ms 4992 KB
subtask1_10.txt WA 20 ms 4992 KB
subtask1_11.txt WA 20 ms 4992 KB
subtask1_12.txt WA 20 ms 4992 KB
subtask1_13.txt WA 19 ms 4992 KB
subtask2_01.txt AC 805 ms 11648 KB
subtask2_02.txt AC 775 ms 18168 KB
subtask2_03.txt AC 744 ms 11264 KB
subtask2_04.txt AC 425 ms 7164 KB
subtask2_05.txt WA 453 ms 8320 KB
subtask2_06.txt AC 782 ms 8188 KB
subtask2_07.txt WA 685 ms 10240 KB
subtask2_08.txt WA 742 ms 14972 KB
subtask2_09.txt WA 704 ms 14972 KB
subtask2_10.txt WA 837 ms 14972 KB
subtask2_11.txt WA 887 ms 14460 KB
subtask2_12.txt AC 731 ms 17404 KB
subtask2_13.txt AC 736 ms 8316 KB