Submission #856038


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][20];
LL solve(int a,int b){
	if(a>=b) return 0;
	REP(i,20){
		int x=20-i-1;
		if(x && doubling[a][x]==doubling[a][x-1]) continue;
		if(doubling[a][x]<b || x==0){
			return (1LL<<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,20){
		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 700
Code Size 1266 Byte
Status AC
Exec Time 378 ms
Memory 17280 KB

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 4 ms 256 KB
subtask1_01.txt AC 4 ms 256 KB
subtask1_02.txt AC 4 ms 256 KB
subtask1_03.txt AC 6 ms 384 KB
subtask1_04.txt AC 7 ms 384 KB
subtask1_05.txt AC 6 ms 384 KB
subtask1_06.txt AC 6 ms 384 KB
subtask1_07.txt AC 5 ms 384 KB
subtask1_08.txt AC 9 ms 384 KB
subtask1_09.txt AC 7 ms 384 KB
subtask1_10.txt AC 7 ms 384 KB
subtask1_11.txt AC 6 ms 384 KB
subtask1_12.txt AC 6 ms 384 KB
subtask1_13.txt AC 6 ms 384 KB
subtask2_01.txt AC 325 ms 17024 KB
subtask2_02.txt AC 378 ms 17152 KB
subtask2_03.txt AC 353 ms 17024 KB
subtask2_04.txt AC 204 ms 11136 KB
subtask2_05.txt AC 240 ms 11264 KB
subtask2_06.txt AC 307 ms 16896 KB
subtask2_07.txt AC 363 ms 17152 KB
subtask2_08.txt AC 358 ms 17152 KB
subtask2_09.txt AC 357 ms 17152 KB
subtask2_10.txt AC 372 ms 17152 KB
subtask2_11.txt AC 358 ms 15872 KB
subtask2_12.txt AC 290 ms 17280 KB
subtask2_13.txt AC 288 ms 16896 KB