結果
問題 |
No.1742 Binary Indexed Train
|
ユーザー |
|
提出日時 | 2023-04-21 18:26:11 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 494 bytes |
コンパイル時間 | 197 ms |
コンパイル使用メモリ | 81,840 KB |
実行使用メモリ | 116,204 KB |
最終ジャッジ日時 | 2024-11-06 12:32:43 |
合計ジャッジ時間 | 7,061 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
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)) - (max(l - 1, 0) // (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) // (1 << i) + cost(v, r, i - 1) for _ in range(q): s, t = map(int, input().split()) print(cost(s, t, n))