답안 #792756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792756 2023-07-25T08:30:48 Z vjudge1 Bitaro's travel (JOI23_travel) C++14
100 / 100
303 ms 5644 KB
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std ;
const ll N = 2e5 ;
ll n, q, x[N + 2], abu[N + 2] ;
signed main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    cin >> n ;
    x[0] = -1e18 ;
    x[n + 1] = 1e18 ;
    for(ll i = 1 ; i <= n ; i++)
        cin >> x[i] ;
    cin >> q ;
    for(ll i = 1 ; i <= n ; i++)
    {
        ll l = i - 1, r = i + 1, now = i ;
        while(l && r <= n)
            if(x[now] - x[l] <= x[r] - x[now])
            {
                ll l1 = 0, r1 = l ;
                while(l1 + 1 < r1)
                {
                    ll mid = (l1 + r1) >> 1 ;
                    if(x[now] - x[mid] <= x[r] - x[now])r1 = mid ;
                    else l1 = mid ;
                }
                abu[i] += x[now] - x[r1] ;
                now = r1 ;
                l = r1 - 1 ;
            }
            else
            {
                ll l1 = r, r1 = n + 1 ;
                while(l1 + 1 < r1)
                {
                    ll mid = (l1 + r1) >> 1 ;
                    if(x[now] - x[l] > x[mid] - x[now])l1 = mid ;
                    else r1 = mid ;
                }
                abu[i] += x[l1] - x[now] ;
                now = l1 ;
                r = l1 + 1 ;
            }
        abu[i] += x[n] - x[1] ;
    }
    while(q--)
    {
        ll pos, l = 0, r = n + 1 ;
        cin >> pos ;
        while(l + 1 < r)
        {
            ll mid = (l + r) >> 1 ;
            if(x[mid] <= pos)l = mid ;
            else r = mid ;
        }
        if(pos - x[l] <= x[r] - pos)
            cout << abu[l] + pos - x[l] ;
        else
            cout << abu[r] + x[r] - pos ;
        cout << '\n' ;
    }
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 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 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 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 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 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 134 ms 3360 KB Output is correct
18 Correct 146 ms 3372 KB Output is correct
19 Correct 146 ms 3416 KB Output is correct
20 Correct 183 ms 3356 KB Output is correct
21 Correct 202 ms 3392 KB Output is correct
22 Correct 199 ms 3432 KB Output is correct
23 Correct 174 ms 3392 KB Output is correct
24 Correct 227 ms 3424 KB Output is correct
25 Correct 236 ms 3392 KB Output is correct
26 Correct 238 ms 3356 KB Output is correct
27 Correct 233 ms 3340 KB Output is correct
28 Correct 222 ms 3436 KB Output is correct
29 Correct 98 ms 3392 KB Output is correct
30 Correct 97 ms 3432 KB Output is correct
31 Correct 101 ms 3364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 169 ms 4836 KB Output is correct
8 Correct 182 ms 4768 KB Output is correct
9 Correct 175 ms 4820 KB Output is correct
10 Correct 228 ms 4832 KB Output is correct
11 Correct 168 ms 4736 KB Output is correct
12 Correct 170 ms 4756 KB Output is correct
13 Correct 35 ms 2252 KB Output is correct
14 Correct 32 ms 844 KB Output is correct
15 Correct 303 ms 5192 KB Output is correct
16 Correct 293 ms 5268 KB Output is correct
17 Correct 288 ms 5196 KB Output is correct
18 Correct 32 ms 2216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 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 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 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 134 ms 3360 KB Output is correct
18 Correct 146 ms 3372 KB Output is correct
19 Correct 146 ms 3416 KB Output is correct
20 Correct 183 ms 3356 KB Output is correct
21 Correct 202 ms 3392 KB Output is correct
22 Correct 199 ms 3432 KB Output is correct
23 Correct 174 ms 3392 KB Output is correct
24 Correct 227 ms 3424 KB Output is correct
25 Correct 236 ms 3392 KB Output is correct
26 Correct 238 ms 3356 KB Output is correct
27 Correct 233 ms 3340 KB Output is correct
28 Correct 222 ms 3436 KB Output is correct
29 Correct 98 ms 3392 KB Output is correct
30 Correct 97 ms 3432 KB Output is correct
31 Correct 101 ms 3364 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 169 ms 4836 KB Output is correct
39 Correct 182 ms 4768 KB Output is correct
40 Correct 175 ms 4820 KB Output is correct
41 Correct 228 ms 4832 KB Output is correct
42 Correct 168 ms 4736 KB Output is correct
43 Correct 170 ms 4756 KB Output is correct
44 Correct 35 ms 2252 KB Output is correct
45 Correct 32 ms 844 KB Output is correct
46 Correct 303 ms 5192 KB Output is correct
47 Correct 293 ms 5268 KB Output is correct
48 Correct 288 ms 5196 KB Output is correct
49 Correct 32 ms 2216 KB Output is correct
50 Correct 218 ms 5576 KB Output is correct
51 Correct 217 ms 5524 KB Output is correct
52 Correct 218 ms 5572 KB Output is correct
53 Correct 284 ms 5552 KB Output is correct
54 Correct 273 ms 5640 KB Output is correct
55 Correct 292 ms 5644 KB Output is correct
56 Correct 134 ms 5556 KB Output is correct
57 Correct 135 ms 5528 KB Output is correct
58 Correct 169 ms 5472 KB Output is correct