Submission #858665


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

#define ll long long
#define SZ(x) ((int)(x).size()) 
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i) 
#define REP(i,a,n) for ( int i=a; i<int(n); i++ )
#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
#define CLR(a, b) memset(a, b, sizeof(a))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
const int N = 1e5 + 7;
const int LOGN = 20;
const int INF = 2e9 + 7;
int n;
int a[N];
int L, Q;
int nxt[LOGN][N];
void ini(){
    REP(i, 0, n) nxt[0][i] = i;
    a[n] = a[n - 1] + L;
    REP(i, 0, n){
        nxt[1][i] = upper_bound(a + i + 1, a + n, a[i] + L) - a - 1;
    }
    REP(i, 2, LOGN){
        REP(j, 0, n){
            nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
        }
    }
}
int query(int l, int r){
    int res = 0;
    FOR(i, 0, LOGN){
        if(nxt[i][l] < r){
            l = nxt[i][l];
            res += i;
        }
    }
    return res + 1;
}
int main(){
#ifdef ac
	freopen("in.txt","r",stdin);
#endif
	//freopen("out.txt","w",stdout);
    scanf("%d", &n);
    REP(i, 0, n) scanf("%d", &a[i]);
    scanf("%d%d", &L, &Q);
    ini();
    while(Q --){
        int l, r;
        scanf("%d%d", &l, &r);
        if(l > r) swap(l, r);
        l --, r --;
        printf("%d\n", query(l, r));
    }
    return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User Cosss
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2006 Byte
Status WA
Exec Time 148 ms
Memory 8704 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:70:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:71:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     REP(i, 0, n) scanf("%d", &a[i]);
                                    ^
./Main.cpp:72:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &L, &Q);
                          ^
./Main.cpp:76:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &l, &r);
                              ^

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 500
Status
AC × 1
AC × 3
WA × 11
AC × 6
WA × 21
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 384 KB
subtask1_01.txt WA 4 ms 384 KB
subtask1_02.txt AC 4 ms 384 KB
subtask1_03.txt WA 5 ms 384 KB
subtask1_04.txt WA 7 ms 384 KB
subtask1_05.txt WA 5 ms 384 KB
subtask1_06.txt WA 5 ms 384 KB
subtask1_07.txt WA 4 ms 384 KB
subtask1_08.txt AC 5 ms 384 KB
subtask1_09.txt WA 5 ms 384 KB
subtask1_10.txt WA 5 ms 384 KB
subtask1_11.txt WA 5 ms 384 KB
subtask1_12.txt WA 5 ms 384 KB
subtask1_13.txt WA 5 ms 384 KB
subtask2_01.txt WA 136 ms 8704 KB
subtask2_02.txt WA 148 ms 8704 KB
subtask2_03.txt WA 139 ms 8704 KB
subtask2_04.txt AC 74 ms 5760 KB
subtask2_05.txt WA 91 ms 5888 KB
subtask2_06.txt AC 116 ms 8576 KB
subtask2_07.txt WA 142 ms 8704 KB
subtask2_08.txt WA 144 ms 8704 KB
subtask2_09.txt WA 148 ms 8704 KB
subtask2_10.txt WA 147 ms 8704 KB
subtask2_11.txt WA 141 ms 8192 KB
subtask2_12.txt WA 88 ms 8704 KB
subtask2_13.txt AC 116 ms 8576 KB