Submission #855595


Source Code Expand

Copy
#include <bits/stdc++.h>
#define FOR(i,a,b) for(LL i=(a);i<(LL)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const LL INF=1LL<<60;
const LL MAX=1e10;
const int BITSIZE=1<<17;
const LL p=7+1e9;
const int SIZE=2*1e5;
LL nums[SIZE];
LL doubling[SIZE][30];
LL solve(int a,int b){
	if(a==b) return 0;
	REP(i,30){
		int x=30-i-1;
		if(doubling[a][x]<=b){
			return (1<<x)+solve(doubling[a][x],b);
		}
	}
}
int main(){
	LL N,L,a,b;
	cin.tie(0);
	cin >> N;
	REP(i,N){
		cin >> nums[i];
	}
	cin >> L;
	nums[N]=INF;
	int s=0;
	LL now=0;
	REP(i,N+1){
		while(nums[i]-nums[s]>L){
			doubling[s++][0]=i-1;
		}
		
	}
	doubling[N][0]=N;

	FOR(j,1,30){
		REP(i,N+1){
			doubling[i][j]=doubling[doubling[i][j-1]][j-1];			
		}
	}
	LL Q;
	cin >> Q;
	REP(i,Q){
		cin >> a >> b;
		if(a>b) swap(a,b);
		printf("%lld\n",solve(a-1,b-1));
	}
	return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User reew2n
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1200 Byte
Status WA
Exec Time 414 ms
Memory 25344 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 500
Status
AC × 1
AC × 1
WA × 13
AC × 1
WA × 26
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 WA 6 ms 256 KB
subtask1_03.txt WA 7 ms 512 KB
subtask1_04.txt WA 7 ms 512 KB
subtask1_05.txt WA 7 ms 512 KB
subtask1_06.txt WA 6 ms 384 KB
subtask1_07.txt WA 5 ms 384 KB
subtask1_08.txt WA 7 ms 512 KB
subtask1_09.txt WA 7 ms 512 KB
subtask1_10.txt WA 7 ms 512 KB
subtask1_11.txt WA 7 ms 512 KB
subtask1_12.txt WA 7 ms 512 KB
subtask1_13.txt WA 6 ms 512 KB
subtask2_01.txt WA 368 ms 24832 KB
subtask2_02.txt WA 414 ms 25088 KB
subtask2_03.txt WA 397 ms 24832 KB
subtask2_04.txt WA 222 ms 16640 KB
subtask2_05.txt WA 250 ms 16384 KB
subtask2_06.txt WA 360 ms 25344 KB
subtask2_07.txt WA 398 ms 24960 KB
subtask2_08.txt WA 402 ms 24960 KB
subtask2_09.txt WA 409 ms 24960 KB
subtask2_10.txt WA 407 ms 24960 KB
subtask2_11.txt WA 397 ms 23040 KB
subtask2_12.txt WA 336 ms 25216 KB
subtask2_13.txt WA 331 ms 24832 KB