結果

問題 No.871 かえるのうた
ユーザー terasaterasa
提出日時 2022-05-31 09:35:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,646 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 99,468 KB
最終ジャッジ日時 2024-09-21 01:10:00
合計ジャッジ時間 7,960 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
56,100 KB
testcase_01 AC 40 ms
55,904 KB
testcase_02 AC 43 ms
55,772 KB
testcase_03 AC 47 ms
56,904 KB
testcase_04 AC 40 ms
55,700 KB
testcase_05 AC 40 ms
55,552 KB
testcase_06 AC 39 ms
56,116 KB
testcase_07 AC 42 ms
55,652 KB
testcase_08 AC 100 ms
77,960 KB
testcase_09 WA -
testcase_10 AC 70 ms
74,192 KB
testcase_11 AC 82 ms
77,436 KB
testcase_12 AC 134 ms
80,412 KB
testcase_13 WA -
testcase_14 AC 234 ms
98,300 KB
testcase_15 WA -
testcase_16 AC 317 ms
99,468 KB
testcase_17 AC 212 ms
97,572 KB
testcase_18 AC 101 ms
79,812 KB
testcase_19 WA -
testcase_20 AC 94 ms
77,812 KB
testcase_21 WA -
testcase_22 AC 40 ms
55,340 KB
testcase_23 AC 41 ms
55,640 KB
testcase_24 AC 39 ms
55,792 KB
testcase_25 WA -
testcase_26 AC 115 ms
78,320 KB
testcase_27 WA -
testcase_28 AC 40 ms
56,112 KB
testcase_29 AC 156 ms
94,432 KB
testcase_30 WA -
testcase_31 AC 90 ms
77,148 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 134 ms
81,204 KB
testcase_35 WA -
testcase_36 AC 195 ms
97,836 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 186 ms
93,468 KB
testcase_41 AC 42 ms
55,408 KB
testcase_42 AC 184 ms
93,588 KB
testcase_43 AC 42 ms
55,828 KB
testcase_44 AC 41 ms
55,708 KB
testcase_45 AC 94 ms
77,292 KB
testcase_46 AC 42 ms
56,152 KB
testcase_47 AC 41 ms
55,392 KB
testcase_48 AC 41 ms
56,532 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] = (l, r)

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