結果

問題 No.1742 Binary Indexed Train
ユーザー 👑 Kazun
提出日時 2021-10-14 17:11:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,301 ms / 3,000 ms
コード長 477 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 104,032 KB
最終ジャッジ日時 2024-12-21 13:16:59
合計ジャッジ時間 32,736 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#================================================
import sys
input=sys.stdin.readline
write=sys.stdout.write

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)

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