結果

問題 No.871 かえるのうた
ユーザー terasaterasa
提出日時 2022-05-31 09:40:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,666 bytes
コンパイル時間 1,684 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 98,784 KB
最終ジャッジ日時 2023-10-21 00:32:51
合計ジャッジ時間 9,427 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,812 KB
testcase_01 AC 45 ms
55,812 KB
testcase_02 AC 46 ms
55,812 KB
testcase_03 AC 46 ms
55,812 KB
testcase_04 AC 48 ms
55,812 KB
testcase_05 AC 48 ms
55,812 KB
testcase_06 AC 46 ms
55,812 KB
testcase_07 AC 47 ms
55,812 KB
testcase_08 AC 113 ms
77,584 KB
testcase_09 WA -
testcase_10 AC 78 ms
73,968 KB
testcase_11 AC 95 ms
76,876 KB
testcase_12 AC 150 ms
79,976 KB
testcase_13 WA -
testcase_14 AC 285 ms
97,712 KB
testcase_15 WA -
testcase_16 AC 376 ms
98,748 KB
testcase_17 AC 252 ms
97,396 KB
testcase_18 AC 118 ms
79,560 KB
testcase_19 WA -
testcase_20 AC 105 ms
77,472 KB
testcase_21 WA -
testcase_22 AC 46 ms
55,812 KB
testcase_23 AC 47 ms
55,812 KB
testcase_24 AC 44 ms
55,812 KB
testcase_25 WA -
testcase_26 AC 134 ms
78,392 KB
testcase_27 WA -
testcase_28 AC 45 ms
55,812 KB
testcase_29 AC 183 ms
93,504 KB
testcase_30 WA -
testcase_31 AC 100 ms
76,864 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 152 ms
80,728 KB
testcase_35 WA -
testcase_36 AC 218 ms
97,532 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 218 ms
93,224 KB
testcase_41 AC 46 ms
55,812 KB
testcase_42 AC 210 ms
93,212 KB
testcase_43 AC 48 ms
55,812 KB
testcase_44 AC 47 ms
55,812 KB
testcase_45 AC 104 ms
77,020 KB
testcase_46 AC 45 ms
55,812 KB
testcase_47 AC 46 ms
55,812 KB
testcase_48 AC 46 ms
55,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


class SegTree:
    def __init__(self, N, func, e):
        self.N = N
        self.func = func
        self.X = [e] * (N << 1)
        self.e = e

    def build(self, seq):
        for i in range(self.N):
            self.X[self.N + i] = seq[i]
        for i in range(self.N)[::-1]:
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def add(self, i, x):
        i += self.N
        self.X[i] += x
        while i > 1:
            i >>= 1
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def update(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1])

    def query(self, L, R):
        L += self.N
        R += self.N
        vL = self.e
        vR = self.e
        while L < R:
            if L & 1:
                vL = self.func(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.func(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.func(vL, vR)


N, K = map(int, input().split())
K -= 1
X = list(map(int, input().split()))
A = list(map(int, input().split()))

left = []
right = []
for i in range(N):
    l = index_ge(X, X[i] - A[i])
    r = index_le(X, X[i] + A[i])
    left.append(l)
    right.append(r)

INF = 1 << 60
lst = SegTree(N, min, INF)
rst = SegTree(N, max, -INF)
lst.build(left)
rst.build(right)

E = [None] * N
for i in range(N):
    l = lst.query(left[i], right[i] + 1)
    r = rst.query(left[i], right[i] + 1)
    E[i] = (max(l, 0), min(r, N - 1))

dq = deque([K])
visited = [False] * N
l = INF
r = -INF
while len(dq) > 0:
    v = dq.popleft()
    if visited[v] is True:
        continue
    visited[v] = True
    l = min(l, v)
    r = max(r, v)

    for d in E[v]:
        if visited[d] is False:
            dq.append(d)
print(r - l + 1)
0