Submission #796018

# Submission time Handle Problem Language Result Execution time Memory
796018 2023-07-28T04:21:26 Z 반딧불(#10068) Bitaro's travel (JOI23_travel) C++17
100 / 100
210 ms 6180 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct segTree{
    int tree[800002];

    void init(int i, int l, int r, int* v){
        if(l==r){
            tree[i] = v[l];
            return;
        }
        int m = (l+r)>>1;
        init(i*2, l, m, v);
        init(i*2+1, m+1, r, v);
        tree[i] = max(tree[i*2], tree[i*2+1]);
    }

    int findRight(int i, int l, int r, int x, int lim){ /// lim �̻��� �� ã��
        if(r<x || tree[i] < lim) return r+1;
        if(l==r) return l;
        int m = (l+r)>>1;
        int tmp = findRight(i*2, l, m, x, lim);
        if(tmp == m+1) return findRight(i*2+1, m+1, r, x, lim);
        else return tmp;
    }

    int findLeft(int i, int l, int r, int x, int lim){
        if(x<l || tree[i] < lim) return l-1;
        if(l==r) return l;
        int m = (l+r)>>1;
        int tmp = findLeft(i*2+1, m+1, r, x, lim);
        if(tmp == m) return findLeft(i*2, l, m, x, lim);
        else return tmp;
    }
} tree;

int n, q;
int arr[200002];
int diff[200002];

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
    for(int i=1; i<n; i++) diff[i] = arr[i+1] - arr[i];
    if(n!=1) tree.init(1, 1, n-1, diff);
    scanf("%d", &q);

    while(q--){
        int start;
        ll ans = 0;
        scanf("%d", &start);
        int idx = lower_bound(arr+1, arr+n+1, start) - arr;

        if(idx == n+1) ans = start - arr[n], start = n;
        else if(idx == 1) ans = arr[1] - start, start = 1;
        else if(arr[idx] - start >= start - arr[idx-1]) ans = start - arr[idx-1], start = idx-1;
        else ans = arr[idx] - start, start = idx;

        int s = start, e = start, x = start;
        while(1<s || e<n){
            if(s==1) ans += arr[n] - arr[x], e = n;
            else if(e==n) ans += arr[x] - arr[1], s = 1;
            else{
                if(arr[x] - arr[s-1] <= arr[e+1] - arr[x]){ /// ���� �������� ���� ��
                    int a = tree.findLeft(1, 1, n-1, x-1, arr[e+1] - arr[x] + 1);
                    a++;
                    ans += arr[x] - arr[a], s = x = a;
                }
                else{ /// ������ �������� ���� ��
                    int a = tree.findRight(1, 1, n-1, x, arr[x] - arr[s-1]);
                    ans += arr[a] - arr[x], e = x = a;
                }
            }
        }

        printf("%lld\n", ans);
    }
}

Compilation message

travel.cpp: In function 'int main()':
travel.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
travel.cpp:46:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~
travel.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
travel.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf("%d", &start);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 19 ms 3900 KB Output is correct
18 Correct 18 ms 3924 KB Output is correct
19 Correct 18 ms 3796 KB Output is correct
20 Correct 18 ms 3920 KB Output is correct
21 Correct 18 ms 3804 KB Output is correct
22 Correct 18 ms 3924 KB Output is correct
23 Correct 18 ms 3796 KB Output is correct
24 Correct 18 ms 3800 KB Output is correct
25 Correct 20 ms 3924 KB Output is correct
26 Correct 18 ms 3824 KB Output is correct
27 Correct 18 ms 3808 KB Output is correct
28 Correct 18 ms 3924 KB Output is correct
29 Correct 18 ms 3796 KB Output is correct
30 Correct 18 ms 3832 KB Output is correct
31 Correct 18 ms 3896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 91 ms 5220 KB Output is correct
8 Correct 90 ms 5248 KB Output is correct
9 Correct 91 ms 5196 KB Output is correct
10 Correct 93 ms 5252 KB Output is correct
11 Correct 92 ms 5216 KB Output is correct
12 Correct 93 ms 5224 KB Output is correct
13 Correct 44 ms 2260 KB Output is correct
14 Correct 36 ms 832 KB Output is correct
15 Correct 103 ms 5608 KB Output is correct
16 Correct 91 ms 5648 KB Output is correct
17 Correct 93 ms 5628 KB Output is correct
18 Correct 46 ms 2220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 19 ms 3900 KB Output is correct
18 Correct 18 ms 3924 KB Output is correct
19 Correct 18 ms 3796 KB Output is correct
20 Correct 18 ms 3920 KB Output is correct
21 Correct 18 ms 3804 KB Output is correct
22 Correct 18 ms 3924 KB Output is correct
23 Correct 18 ms 3796 KB Output is correct
24 Correct 18 ms 3800 KB Output is correct
25 Correct 20 ms 3924 KB Output is correct
26 Correct 18 ms 3824 KB Output is correct
27 Correct 18 ms 3808 KB Output is correct
28 Correct 18 ms 3924 KB Output is correct
29 Correct 18 ms 3796 KB Output is correct
30 Correct 18 ms 3832 KB Output is correct
31 Correct 18 ms 3896 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 91 ms 5220 KB Output is correct
39 Correct 90 ms 5248 KB Output is correct
40 Correct 91 ms 5196 KB Output is correct
41 Correct 93 ms 5252 KB Output is correct
42 Correct 92 ms 5216 KB Output is correct
43 Correct 93 ms 5224 KB Output is correct
44 Correct 44 ms 2260 KB Output is correct
45 Correct 36 ms 832 KB Output is correct
46 Correct 103 ms 5608 KB Output is correct
47 Correct 91 ms 5648 KB Output is correct
48 Correct 93 ms 5628 KB Output is correct
49 Correct 46 ms 2220 KB Output is correct
50 Correct 210 ms 6096 KB Output is correct
51 Correct 168 ms 6092 KB Output is correct
52 Correct 155 ms 6016 KB Output is correct
53 Correct 160 ms 6076 KB Output is correct
54 Correct 148 ms 6180 KB Output is correct
55 Correct 169 ms 6088 KB Output is correct
56 Correct 72 ms 5968 KB Output is correct
57 Correct 72 ms 6032 KB Output is correct
58 Correct 72 ms 6008 KB Output is correct