Submission #864411


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 popcount32(unsigned int x) {
#if defined(_MSC_VER)
	return __popcnt(x);
#else
	return __builtin_popcount(x);
#endif
}

class BIT_01 {
	BIT bit;
	std::vector<unsigned int> b;
public:
	BIT_01(int size) :bit((size+31)/32 + 1), b((size + 31) / 32) {}
	void on(unsigned int i) {
		if (b[i / 32] >> i % 32 & 1)return;
		b[i / 32] |= 1 << i % 32;
		bit.add(i / 32 + 1, 1);
	}
	void off(unsigned int i) {
		if (!(b[i / 32] >> i % 32 & 1))return;
		b[i / 32] &= ~(1 << i % 32);
		bit.add(i / 32 + 1, -1);
	}
	int rank(unsigned int i)const { //[0,i)
		return bit.sum(i / 32) + popcount32(b[i / 32] & ((1 << i % 32) - 1));
	}
};





int ans[100000];


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



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

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

	bit.on(u);
	for (int v : child[u]) {
		dfs(v);
	}
	bit.off(u);
}


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 2451 Byte
Status AC
Exec Time 142 ms
Memory 19200 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:113:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
./Main.cpp:114: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:115: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:118: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 4992 KB
subtask1_01.txt AC 14 ms 4992 KB
subtask1_02.txt AC 15 ms 4992 KB
subtask1_03.txt AC 12 ms 4992 KB
subtask1_04.txt AC 13 ms 5120 KB
subtask1_05.txt AC 13 ms 4992 KB
subtask1_06.txt AC 12 ms 4992 KB
subtask1_07.txt AC 13 ms 4992 KB
subtask1_08.txt AC 12 ms 4992 KB
subtask1_09.txt AC 13 ms 4992 KB
subtask1_10.txt AC 12 ms 5120 KB
subtask1_11.txt AC 12 ms 4992 KB
subtask1_12.txt AC 13 ms 4992 KB
subtask1_13.txt AC 13 ms 4992 KB
subtask2_01.txt AC 126 ms 11776 KB
subtask2_02.txt AC 142 ms 19200 KB
subtask2_03.txt AC 137 ms 11264 KB
subtask2_04.txt AC 75 ms 7168 KB
subtask2_05.txt AC 84 ms 8448 KB
subtask2_06.txt AC 103 ms 8192 KB
subtask2_07.txt AC 130 ms 10368 KB
subtask2_08.txt AC 133 ms 15616 KB
subtask2_09.txt AC 142 ms 15616 KB
subtask2_10.txt AC 139 ms 15616 KB
subtask2_11.txt AC 135 ms 14976 KB
subtask2_12.txt AC 126 ms 18432 KB
subtask2_13.txt AC 104 ms 8192 KB