Submission #864158


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


class BIT {
	std::vector<int> bit;
public:
	BIT(int size) :bit(size + 1, 0) {}
	void add(int i, int x) {//i番目にx加える
		i++;//BIT添え字は1~nだから
		while (i<(int)bit.size()) {
			bit[i] += x;
			i += i&-i;
		}
	}
	int sum(int a)const {//[0,a]の和
		a++;
		int res = 0;
		while (0<a) {
			res += bit[a];
			a -= a&-a;
		}
		return res;
	}
	int sum(int a, int b)const {//[a,b]の合計
		return sum(b) - sum(a - 1);
	}
};



int ans[100000];


vector<pair<int,int>> query[100000];
vector<int> child[100000];
BIT bit(100000);



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

void dfs(int u) {
	for (auto p : query[u]) {
		ans[p.second] = bit.sum(p.first - 1) + 1;
	}

	bit.add(u, 1);
	for (int v : child[u]) {
		dfs(v);
	}
	bit.add(u, -1);
}


int main() {
	scanf("%d", &N);
	rep(i, N)scanf("%d", x + i);
	scanf("%d%d", &L, &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);
	}
	dfs(N - 1);
	rep(i, Q)printf("%d\n", ans[i]);

	return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User hirokazu1020
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1802 Byte
Status AC
Exec Time 136 ms
Memory 14848 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:82:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
./Main.cpp:83: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:84:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &L, &Q);
                       ^
./Main.cpp:87: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 13 ms 5376 KB
subtask1_01.txt AC 13 ms 5376 KB
subtask1_02.txt AC 13 ms 5376 KB
subtask1_03.txt AC 13 ms 5376 KB
subtask1_04.txt AC 14 ms 5376 KB
subtask1_05.txt AC 13 ms 5376 KB
subtask1_06.txt AC 13 ms 5376 KB
subtask1_07.txt AC 12 ms 5376 KB
subtask1_08.txt AC 14 ms 5376 KB
subtask1_09.txt AC 13 ms 5376 KB
subtask1_10.txt AC 13 ms 5376 KB
subtask1_11.txt AC 14 ms 5376 KB
subtask1_12.txt AC 13 ms 5376 KB
subtask1_13.txt AC 12 ms 5376 KB
subtask2_01.txt AC 129 ms 11776 KB
subtask2_02.txt AC 136 ms 14848 KB
subtask2_03.txt AC 135 ms 11648 KB
subtask2_04.txt AC 74 ms 7676 KB
subtask2_05.txt AC 84 ms 8448 KB
subtask2_06.txt AC 107 ms 8576 KB
subtask2_07.txt AC 131 ms 10240 KB
subtask2_08.txt AC 132 ms 12928 KB
subtask2_09.txt AC 128 ms 12928 KB
subtask2_10.txt AC 135 ms 12928 KB
subtask2_11.txt AC 129 ms 12416 KB
subtask2_12.txt AC 113 ms 14208 KB
subtask2_13.txt AC 102 ms 8572 KB