Submission #857399


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;
    }
    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]];
        }
    }
}
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);
        if(b<c)
        {
            for(int 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;
                }
            }
        }
        else
        {
            for(int 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;
                }
            }
        }
        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 0
Code Size 2244 Byte
Status WA
Exec Time 230 ms
Memory 25088 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:57:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:58: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:59:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&p);
                     ^
./Main.cpp:62:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&q);
                   ^
./Main.cpp:66: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 0 / 200 0 / 500
Status
AC × 1
AC × 1
WA × 13
AC × 1
WA × 26
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 36 ms 23680 KB
subtask1_01.txt WA 42 ms 23680 KB
subtask1_02.txt WA 42 ms 23680 KB
subtask1_03.txt WA 42 ms 23680 KB
subtask1_04.txt WA 37 ms 23680 KB
subtask1_05.txt WA 42 ms 23680 KB
subtask1_06.txt WA 37 ms 23680 KB
subtask1_07.txt WA 42 ms 23680 KB
subtask1_08.txt WA 37 ms 23680 KB
subtask1_09.txt WA 42 ms 23680 KB
subtask1_10.txt WA 37 ms 23680 KB
subtask1_11.txt WA 42 ms 23680 KB
subtask1_12.txt WA 37 ms 23680 KB
subtask1_13.txt WA 42 ms 23680 KB
subtask2_01.txt WA 211 ms 24960 KB
subtask2_02.txt WA 230 ms 25088 KB
subtask2_03.txt WA 208 ms 24832 KB
subtask2_04.txt WA 122 ms 24320 KB
subtask2_05.txt WA 147 ms 24448 KB
subtask2_06.txt WA 168 ms 24704 KB
subtask2_07.txt WA 229 ms 24960 KB
subtask2_08.txt WA 225 ms 24960 KB
subtask2_09.txt WA 228 ms 24960 KB
subtask2_10.txt WA 226 ms 24960 KB
subtask2_11.txt WA 216 ms 24960 KB
subtask2_12.txt WA 139 ms 25088 KB
subtask2_13.txt WA 225 ms 24704 KB