Submission #863369


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() {
	scanf("%d", &N);
	rep(i, N)scanf("%d", x + i);
	scanf("%d", &L);
	scanf("%d", &Q);
	rep(i, Q) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		if (a > b)swap(a, b);
		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);
	}
	par.reserve(N);
	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 700
Code Size 1405 Byte
Status AC
Exec Time 859 ms
Memory 18048 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:56:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
./Main.cpp:57:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i, N)scanf("%d", x + i);
                             ^
./Main.cpp:58:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &L);
                 ^
./Main.cpp:59:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
                 ^
./Main.cpp:62:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
                        ^

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 11 ms 4992 KB
subtask1_01.txt AC 11 ms 4992 KB
subtask1_02.txt AC 11 ms 4992 KB
subtask1_03.txt AC 20 ms 4992 KB
subtask1_04.txt AC 20 ms 4992 KB
subtask1_05.txt AC 20 ms 4992 KB
subtask1_06.txt AC 16 ms 4992 KB
subtask1_07.txt AC 14 ms 4992 KB
subtask1_08.txt AC 17 ms 4992 KB
subtask1_09.txt AC 20 ms 4992 KB
subtask1_10.txt AC 20 ms 4992 KB
subtask1_11.txt AC 20 ms 4992 KB
subtask1_12.txt AC 20 ms 4992 KB
subtask1_13.txt AC 19 ms 4992 KB
subtask2_01.txt AC 693 ms 11648 KB
subtask2_02.txt AC 708 ms 18048 KB
subtask2_03.txt AC 707 ms 11264 KB
subtask2_04.txt AC 526 ms 7164 KB
subtask2_05.txt AC 537 ms 8320 KB
subtask2_06.txt AC 797 ms 8192 KB
subtask2_07.txt AC 834 ms 10240 KB
subtask2_08.txt AC 855 ms 14848 KB
subtask2_09.txt AC 859 ms 14848 KB
subtask2_10.txt AC 714 ms 14848 KB
subtask2_11.txt AC 705 ms 14208 KB
subtask2_12.txt AC 684 ms 17280 KB
subtask2_13.txt AC 662 ms 8188 KB