Contest Duration: - (local time) (100 minutes) Back to Home

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 2016-08-28 21:23:00+0900 E - Tak and Hotels kmjp C++14 (GCC 5.4.1) 700 1170 Byte AC 858 ms 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
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