Submission #856891


Source Code Expand

Copy
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}


int N, L, Q, pow2[22];
lint x[100010], rx[100010];
Vec< Vec< int > > par, rpar;

void preProc(lint *xx, Vec< Vec< int > >& pp) {
	Vec< lint > sum(N + 10, 0);
	for_(i,0,N + 5) sum[i + 1] = sum[i] + abs(xx[i + 1] - xx[i]);
	
	for_(i,0,N) {
		int lb = i + 1, ub = N;
		
		while (ub - lb > 1) {
			int med = (lb + ub) / 2;
			lint dst = sum[med] - sum[i];
			if (dst > (lint)L) ub = med;
			else lb = med;
		}
		
		pp[i][0] = lb;
	}
	
	for_(k,0,20) for_(i,0,N) {
		if (pp[i][k] < 0) pp[i][k] = -1;
		else pp[i][k + 1] = pp[ pp[i][k] ][k];
	}
}

void query(int a, int b, Vec< Vec< int > >& par) {
	//cerr << a << " " << b << endl;
	int ans = 0;
	
	for_rev(k,20,0) {
		if (par[a][k] < 0) continue;
		if (b < par[a][k]) continue;
		
		a = par[a][k];
		ans += pow2[k];
		
		if (a == b) {
			printf("%d\n", ans);
			return;
		}
		
		if (b <= par[a][0]) {
			printf("%d\n", ans + 1);
			return;
		}
	}
}

int main() {
	cin >> N;
	for_(i,0,N) {
		cin >> x[i];
		rx[N - i - 1] = x[i];
	}
	
	cin >> L;
	x[N] = L;
	rx[N] = L;
	
	par.assign(N + 10, Vec< int >(25, -1));
	preProc(x, par);
	/*
	for_(i,0,N) {
		for_(k,0,20) cerr << par[i][k] << " ";
		cerr << endl;
	}
	*/	
	rpar.assign(N + 10, Vec< int >(25, -1));
	preProc(rx, rpar);
	
	pow2[0] = 1;
	for_(i,1,22) pow2[i] = pow2[i - 1] * 2;
	
	cin >> Q;
	
	for_(q,0,Q) {
		int a, b;
		scanf("%d %d", &a, &b);
		--a; --b;
		if (a < b) query(a, b, par);
		else query(N - a - 1, N - b - 1, rpar);
	}
}

Submission Info

Submission Time
Task E - Tak and Hotels
User tsukasa_diary
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3525 Byte
Status WA
Exec Time 367 ms
Memory 29680 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:132:25: 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 0 / 200 0 / 500
Status
AC × 1
AC × 5
WA × 9
AC × 7
WA × 20
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 4 ms 256 KB
subtask1_01.txt WA 4 ms 256 KB
subtask1_02.txt AC 4 ms 256 KB
subtask1_03.txt WA 6 ms 512 KB
subtask1_04.txt AC 6 ms 512 KB
subtask1_05.txt WA 6 ms 512 KB
subtask1_06.txt AC 5 ms 384 KB
subtask1_07.txt WA 5 ms 384 KB
subtask1_08.txt WA 6 ms 512 KB
subtask1_09.txt WA 7 ms 512 KB
subtask1_10.txt WA 6 ms 512 KB
subtask1_11.txt AC 7 ms 512 KB
subtask1_12.txt WA 6 ms 512 KB
subtask1_13.txt WA 6 ms 512 KB
subtask2_01.txt WA 335 ms 29552 KB
subtask2_02.txt AC 367 ms 29680 KB
subtask2_03.txt WA 336 ms 29552 KB
subtask2_04.txt WA 158 ms 19196 KB
subtask2_05.txt WA 205 ms 19452 KB
subtask2_06.txt WA 248 ms 29168 KB
subtask2_07.txt WA 321 ms 29552 KB
subtask2_08.txt WA 349 ms 29680 KB
subtask2_09.txt WA 348 ms 29680 KB
subtask2_10.txt WA 352 ms 29680 KB
subtask2_11.txt WA 338 ms 27440 KB
subtask2_12.txt AC 250 ms 29680 KB
subtask2_13.txt WA 247 ms 29296 KB