Submission #855528


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int L;
int Q;
int X[101010];
int ne[101010][20];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>X[i];
	cin>>L;
	
	FOR(i,N) ne[i][0]=lower_bound(X+i,X+N,X[i]+L+1)-1-X;
	FOR(i,19) {
		FOR(x,N) ne[x][i+1]=ne[ne[x][i]][i];
	}
	
	cin>>Q;
	while(Q--) {
		cin>>x>>y;
		x--,y--;
		if(x>y) swap(x,y);
		
		int day=0;
		for(i=19;i>=0;i--) {
			if(ne[x][i]<y) {
				x=ne[x][i];
				day+=1<<i;
			}
		}
		
		cout<<day+1<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User kmjp
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1170 Byte
Status AC
Exec Time 858 ms
Memory 9088 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 10 ms 384 KB
subtask1_04.txt AC 11 ms 384 KB
subtask1_05.txt AC 11 ms 384 KB
subtask1_06.txt AC 7 ms 256 KB
subtask1_07.txt AC 7 ms 256 KB
subtask1_08.txt AC 13 ms 384 KB
subtask1_09.txt AC 11 ms 384 KB
subtask1_10.txt AC 11 ms 384 KB
subtask1_11.txt AC 11 ms 384 KB
subtask1_12.txt AC 11 ms 384 KB
subtask1_13.txt AC 12 ms 384 KB
subtask2_01.txt AC 854 ms 8960 KB
subtask2_02.txt AC 808 ms 9088 KB
subtask2_03.txt AC 719 ms 8832 KB
subtask2_04.txt AC 441 ms 5760 KB
subtask2_05.txt AC 552 ms 5888 KB
subtask2_06.txt AC 670 ms 8704 KB
subtask2_07.txt AC 858 ms 8960 KB
subtask2_08.txt AC 714 ms 8960 KB
subtask2_09.txt AC 857 ms 8960 KB
subtask2_10.txt AC 715 ms 8960 KB
subtask2_11.txt AC 740 ms 8320 KB
subtask2_12.txt AC 665 ms 9088 KB
subtask2_13.txt AC 676 ms 8704 KB