Submission #855986


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <queue>
#include <cstring>
#include <set>
#include <list>
#include <map>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vvi> vvvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;

#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define forn(i, a, b) for(int i = a; i < b; i++)

#define pb push_back
#define mp make_pair

int main()
{

    int n;
    scanf("%d", &n);
    vi x(n);
    forn(i,0,n) scanf("%d", &x[i]);
    int l;
    scanf("%d", &l);
    int q;
    scanf("%d", &q);
    vvi d(20, vi(n));
    forn(i,0,n) {
        d[0][i] = (upper_bound(all(x), x[i] + l) - x.begin()) - 1;
    }
    forn(k,1,20) {
        forn(i,0,n) {
            d[k][i] = d[k-1][d[k-1][i]];
        }
    }
    vi d2(1,1);
    forn(i,0,20) d2.pb(d2.back()*2);
    forn(i,0,q) {
        int a,b;
        scanf("%d %d", &a, &b);
        if(a>b) swap(a,b);
        a--;
        b--;
        int ans = 0;
        int cur = 19;
        while(cur>=0) {
            if(d[cur][a] < b) {
                a = d[cur][a];
                ans += d2[cur];
            }
            cur--;
        }
        if(a<b) ans++;
        printf("%d\n", ans);
    }
    
    
}

Submission Info

Submission Time
Task E - Tak and Hotels
User Vercingetorix
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1824 Byte
Status AC
Exec Time 154 ms
Memory 9080 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:46:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:48:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     forn(i,0,n) scanf("%d", &x[i]);
                                   ^
./Main.cpp:50:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &l);
                    ^
./Main.cpp:52:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
                    ^
./Main.cpp:66:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
                      ...

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 5 ms 384 KB
subtask1_04.txt AC 5 ms 384 KB
subtask1_05.txt AC 5 ms 384 KB
subtask1_06.txt AC 4 ms 256 KB
subtask1_07.txt AC 4 ms 256 KB
subtask1_08.txt AC 4 ms 384 KB
subtask1_09.txt AC 5 ms 384 KB
subtask1_10.txt AC 5 ms 384 KB
subtask1_11.txt AC 5 ms 384 KB
subtask1_12.txt AC 5 ms 384 KB
subtask1_13.txt AC 5 ms 384 KB
subtask2_01.txt AC 141 ms 8952 KB
subtask2_02.txt AC 154 ms 9080 KB
subtask2_03.txt AC 139 ms 8832 KB
subtask2_04.txt AC 76 ms 6016 KB
subtask2_05.txt AC 93 ms 6012 KB
subtask2_06.txt AC 114 ms 8832 KB
subtask2_07.txt AC 145 ms 8952 KB
subtask2_08.txt AC 154 ms 9080 KB
subtask2_09.txt AC 151 ms 9080 KB
subtask2_10.txt AC 153 ms 9080 KB
subtask2_11.txt AC 149 ms 8344 KB
subtask2_12.txt AC 98 ms 9080 KB
subtask2_13.txt AC 112 ms 8832 KB