Submission #856166


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[maxn],r[maxn];
ll a[maxn],p;
void init()
{
    for(int i=0;i<=n-1;i++)
    {
        r[i]=lower_bound(a,a+n,a[i]+p)-a;
        if(r[i]==n||a[r[i]]>a[i]+p)r[i]--;
        l[i]=lower_bound(a,a+n,a[i]-p)-a;
    }
}
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)
        {
            ans=0;
            while(b<c)ans++,b=r[b];
        }
        else
        {
            ans=0;
            while(b>c)ans++,b=l[b];
        }
        printf("%d\n",ans);
    }
    //system("Pause");
    return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User mxzf0213
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1580 Byte
Status TLE
Exec Time 3157 ms
Memory 2304 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:47:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:48: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:49:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&p);
                     ^
./Main.cpp:52:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&q);
                   ^
./Main.cpp:56: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

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 0 / 500
Status
AC × 1
AC × 14
AC × 21
TLE × 6
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 5 ms 256 KB
subtask1_04.txt AC 6 ms 256 KB
subtask1_05.txt AC 5 ms 256 KB
subtask1_06.txt AC 5 ms 256 KB
subtask1_07.txt AC 4 ms 256 KB
subtask1_08.txt AC 5 ms 256 KB
subtask1_09.txt AC 7 ms 256 KB
subtask1_10.txt AC 6 ms 256 KB
subtask1_11.txt AC 6 ms 256 KB
subtask1_12.txt AC 6 ms 256 KB
subtask1_13.txt AC 6 ms 256 KB
subtask2_01.txt AC 1681 ms 2304 KB
subtask2_02.txt TLE 3157 ms 1920 KB
subtask2_03.txt AC 626 ms 2176 KB
subtask2_04.txt AC 57 ms 1408 KB
subtask2_05.txt AC 902 ms 1536 KB
subtask2_06.txt AC 81 ms 2048 KB
subtask2_07.txt AC 2275 ms 2304 KB
subtask2_08.txt TLE 3157 ms 2048 KB
subtask2_09.txt TLE 3153 ms 2048 KB
subtask2_10.txt TLE 3156 ms 2048 KB
subtask2_11.txt TLE 3157 ms 1920 KB
subtask2_12.txt TLE 3153 ms 1792 KB
subtask2_13.txt AC 83 ms 2048 KB