結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
57,016 KB
testcase_01 AC 40 ms
55,708 KB
testcase_02 AC 42 ms
56,240 KB
testcase_03 AC 42 ms
56,408 KB
testcase_04 AC 40 ms
55,580 KB
testcase_05 AC 42 ms
55,968 KB
testcase_06 AC 40 ms
55,836 KB
testcase_07 AC 42 ms
55,460 KB
testcase_08 AC 98 ms
77,804 KB
testcase_09 WA -
testcase_10 AC 71 ms
74,396 KB
testcase_11 AC 85 ms
77,588 KB
testcase_12 AC 140 ms
80,200 KB
testcase_13 WA -
testcase_14 AC 243 ms
97,776 KB
testcase_15 WA -
testcase_16 AC 334 ms
99,400 KB
testcase_17 AC 211 ms
97,700 KB
testcase_18 AC 103 ms
79,604 KB
testcase_19 WA -
testcase_20 AC 97 ms
77,928 KB
testcase_21 WA -
testcase_22 AC 42 ms
55,424 KB
testcase_23 AC 43 ms
55,168 KB
testcase_24 AC 41 ms
55,168 KB
testcase_25 WA -
testcase_26 AC 124 ms
78,592 KB
testcase_27 WA -
testcase_28 AC 42 ms
55,424 KB
testcase_29 AC 160 ms
94,080 KB
testcase_30 WA -
testcase_31 AC 92 ms
77,088 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 136 ms
81,528 KB
testcase_35 WA -
testcase_36 AC 187 ms
97,948 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 191 ms
93,440 KB
testcase_41 AC 45 ms
54,656 KB
testcase_42 AC 199 ms
93,440 KB
testcase_43 AC 43 ms
55,296 KB
testcase_44 AC 43 ms
55,680 KB
testcase_45 AC 98 ms
77,312 KB
testcase_46 AC 44 ms
54,912 KB
testcase_47 AC 43 ms
54,784 KB
testcase_48 AC 43 ms
55,296 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