結果
問題 |
No.1742 Binary Indexed Train
|
ユーザー |
|
提出日時 | 2023-04-21 18:29:08 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 480 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,228 KB |
実行使用メモリ | 117,528 KB |
最終ジャッジ日時 | 2024-11-06 12:34:45 |
合計ジャッジ時間 | 5,617 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | TLE * 1 -- * 31 |
ソースコード
from functools import lru_cache n, q = map(int, input().split()) @lru_cache def cost(l, r, i): if i == 0: return r - l else: cnt = r // (1 << i) - (l - 1) // (1 << i) if cnt < 2: return cost(l, r, i - 1) else: u = ((l + (1 << i) - 1) // (1 << i)) * (1 << i) v = (r // (1 << i)) * (1 << i) return cost(l, u, i - 1) + (v - u) // (1 << i) + cost(v, r, i - 1) for _ in range(q): s, t = map(int, input().split()) print(cost(s, t, n))