結果

問題 No.1742 Binary Indexed Train
ユーザー Shirotsume
提出日時 2021-11-09 22:43:34
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 410 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 27,648 KB
最終ジャッジ日時 2024-11-25 11:18:10
合計ジャッジ時間 84,448 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 TLE * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
@lru_cache
def solve(S,T,l,r):
    if T<=l or r<=S:
        return 0
    elif S<=l and r<=T:
        return 1
    else:
        m=(l+r)>>1
        x=solve(S,T,l,m)
        y=solve(S,T,m,r)
        return x+y


N,Q=map(int,input().split())

Max=1<<N
Ans=[0]*Q
for quest in range(Q):
    S,T=map(int,input().split())
    Ans[quest]=solve(S,T,0,Max)

print("\n".join(map(str,Ans)))
0