結果
問題 | No.1742 Binary Indexed Train |
ユーザー | nawawan |
提出日時 | 2021-11-12 23:01:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,287 ms / 3,000 ms |
コード長 | 837 bytes |
コンパイル時間 | 2,103 ms |
コンパイル使用メモリ | 195,936 KB |
最終ジャッジ日時 | 2025-01-25 17:25:17 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int Q; cin >> Q; vector<long long> ni(N + 1); ni[0] = 1; for(int i = 1; i <= N; i++) ni[i] = ni[i - 1] * 2; while(Q--){ long long S, T; cin >> S >> T; int id = -1; bool f = true; int ans = 0; while(S < T){ int pre = id; for(int i = id; i < N; i++){ if(S % ni[i + 1] == 0 && S + ni[i + 1] <= T){ id = i + 1; } } if(pre == id) break; else { ans++; S += ni[id]; } } long long rest = T - S; while(rest){ if(rest & 1) ans++; rest >>= 1; } cout << ans << endl; } }