library_for_python

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Kazun1998/library_for_python

:warning: Binary_Search/Index.py

Code

def Binary_Search_Index(A, x, sort=False, default=None, offset=0):
    """ 二分探索によって, A に x が存在するれば, そのインデックスを返す.
    (x が複数ある時, 返ってくるインデックスは不定)

    A: リスト
    x: 調べる要素
    sort: ソートをする必要があるかどうか (True で必要)
    default: 存在しなかった場合の返り値
    offset=0: インデックス+ offset の値を返す.
    """
    if sort:
        A.sort()

    if len(A)==0 or x<A[0] or A[-1]<x:
        return default

    L,R=0,len(A)
    while R-L>0:
        C=L+(R-L)//2
        if x<A[C]:
            R=C
        elif x>A[C]:
            L=C+1
        else:
            return C+offset
    return default
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.13.3/x64/lib/python3.13/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.3/x64/lib/python3.13/site-packages/onlinejudge_verify/languages/python.py", line 96, in bundle
    raise NotImplementedError
NotImplementedError
Back to top page