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

Submission #857501

Source Code Expand

Copy
```#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000000
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t,l[30][maxn],r[30][maxn];
ll a[maxn],p;
void init()
{
memset(l,-1,sizeof l);
memset(r,-1,sizeof r);
for(int i=0;i<=n-1;i++)
{
r[0][i]=lower_bound(a,a+n,a[i]+p)-a;
if(r[0][i]==n||a[r[0][i]]>a[i]+p)r[0][i]--;
l[0][i]=lower_bound(a,a+n,a[i]-p)-a;
if(i==n-1)r[0][i]=-1;
if(i==0)l[0][i]=-1;
}
for(int i=1;i<=29;i++)
{
for(int j=0;j<=n-1;j++)
{
if(r[i-1][j]<n-1)r[i][j]=r[i-1][r[i-1][j]];
if(l[i-1][j]>0)l[i][j]=l[i-1][l[i-1][j]];
//if(l[i][j]!=-1)printf("%d %d %d\n",i,j,l[i][j]);
}
}
}
int main()
{
int i,j;
scanf("%d",&n);
rep(i,0,n-1)scanf("%lld",&a[i]);
scanf("%lld",&p);
init();
int q;
scanf("%d",&q);
while(q--)
{
int b,c,ans=0;
scanf("%d%d",&b,&c);
b--,c--;
if(b<c)
{
for(i=29;i>=0;i--)
{
if(r[i][b]!=-1&&r[i][b]<=c)
{
ans+=qpow(2,i);
b=r[i][b];
if(b==c)break;
}
}
if(i==-1)ans++;
}
else
{
for(i=29;i>=0;i--)
{
if(l[i][b]!=-1&&l[i][b]>=c)
{
ans+=qpow(2,i);
b=l[i][b];
if(b==c)break;
}
}
if(i==-1)ans++;
}
printf("%d\n",ans);
}
//system("Pause");
return 0;
}
```

#### Submission Info

Submission Time 2016-08-28 23:22:23+0900 E - Tak and Hotels mxzf0213 C++14 (GCC 5.4.1) 700 2436 Byte AC 245 ms 25088 KB

#### Compile Error

```./Main.cpp: In function ‘int main()’:
./Main.cpp:60:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:61:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
rep(i,0,n-1)scanf("%lld",&a[i]);
^
./Main.cpp:62:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&p);
^
./Main.cpp:65:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&q);
^
./Main.cpp:69:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&b,&c);
...```

#### Judge Result

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 41 ms 23680 KB
subtask1_01.txt AC 41 ms 23680 KB
subtask1_02.txt AC 41 ms 23680 KB
subtask1_03.txt AC 42 ms 23680 KB
subtask1_04.txt AC 42 ms 23680 KB
subtask1_05.txt AC 42 ms 23680 KB
subtask1_06.txt AC 42 ms 23680 KB
subtask1_07.txt AC 41 ms 23680 KB
subtask1_08.txt AC 42 ms 23680 KB
subtask1_09.txt AC 42 ms 23680 KB
subtask1_10.txt AC 42 ms 23680 KB
subtask1_11.txt AC 41 ms 23680 KB
subtask1_12.txt AC 42 ms 23680 KB
subtask1_13.txt AC 42 ms 23680 KB
subtask2_01.txt AC 220 ms 24960 KB
subtask2_02.txt AC 236 ms 25088 KB
subtask2_03.txt AC 217 ms 24832 KB
subtask2_04.txt AC 123 ms 24320 KB
subtask2_05.txt AC 150 ms 24448 KB
subtask2_06.txt AC 175 ms 24704 KB
subtask2_07.txt AC 226 ms 24960 KB
subtask2_08.txt AC 234 ms 24960 KB
subtask2_09.txt AC 245 ms 24960 KB
subtask2_10.txt AC 242 ms 24960 KB
subtask2_11.txt AC 224 ms 24960 KB
subtask2_12.txt AC 145 ms 25088 KB
subtask2_13.txt AC 178 ms 24704 KB