Submission #1407836


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll func(ll b, ll n) {
	if (n < b)
		return n;
	return func(b, n/b) + n%b;
}

signed main() {
	int n,l,q;
	scnaf("%d", &n);
	vector<int> h(n);
	REP(i, n) {
		scnaf("%d", &h[i]);
	}

	scanf("%d %d", &l, &q);

	int db[100001][31] = {};
	
	REP(i, n) {
		db[i][0] = upper_bound(ALL(h), h[i] + l) - h.begin() - 1;
	}

		rep(j, 1, 31) {
	REP(i, n) {
			db[i][j] = db[db[i][j-1]][j - 1];
		}
	}

	REP(i, q) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--, b--;
		if (b < a)
			swap(a, b);

		ll ans = 0;

		int now = a;

		while (now != b) {
			if (b < db[now][0]) {
				ans++;
				break;
			}
			auto buf = upper_bound(begin(db[now]), end(db[now]), b);
			buf--;
			ans += (ll)(1 << (buf - begin(db[now])));
			now = *buf;
		}

		printf("%lld\n", ans);
	}

	return 0;
}

Submission Info

Submission Time
Task C - Tak and Cards
User Gear
Language C++14 (Clang 3.8.0)
Score 0
Code Size 2337 Byte
Status WA
Exec Time 5 ms
Memory 12416 KB

Compile Error

./Main.cpp:9:20: warning: extra tokens at end of #include directive [-Wextra-tokens]
#include <stdlib.h>>
                   ^
                   //
1 warning generated.

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 100
Status
WA × 4
WA × 12
WA × 24
Set Name Test Cases
Sample example_01.txt, example_02.txt, example_03.txt, example_04.txt
Subtask1 example_01.txt, example_02.txt, example_03.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
All example_01.txt, example_02.txt, example_03.txt, example_04.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, 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
Case Name Status Exec Time Memory
example_01.txt WA 4 ms 12416 KB
example_02.txt WA 4 ms 12416 KB
example_03.txt WA 4 ms 12416 KB
example_04.txt WA 4 ms 12416 KB
subtask1_01.txt WA 4 ms 12416 KB
subtask1_02.txt WA 4 ms 12416 KB
subtask1_03.txt WA 4 ms 12416 KB
subtask1_04.txt WA 4 ms 12416 KB
subtask1_05.txt WA 4 ms 12416 KB
subtask1_06.txt WA 4 ms 12416 KB
subtask1_07.txt WA 5 ms 12416 KB
subtask1_08.txt WA 5 ms 12416 KB
subtask1_09.txt WA 4 ms 12416 KB
subtask2_01.txt WA 4 ms 12416 KB
subtask2_02.txt WA 5 ms 12416 KB
subtask2_03.txt WA 5 ms 12416 KB
subtask2_04.txt WA 5 ms 12416 KB
subtask2_05.txt WA 4 ms 12416 KB
subtask2_06.txt WA 4 ms 12416 KB
subtask2_07.txt WA 4 ms 12416 KB
subtask2_08.txt WA 4 ms 12416 KB
subtask2_09.txt WA 4 ms 12416 KB
subtask2_10.txt WA 4 ms 12416 KB
subtask2_11.txt WA 4 ms 12416 KB