結果

問題 No.1742 Binary Indexed Train
ユーザー nawawannawawan
提出日時 2021-11-12 23:01:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,243 ms / 3,000 ms
コード長 837 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 201,192 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 03:30:16
合計ジャッジ時間 30,120 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2,036 ms
4,380 KB
testcase_04 AC 2,040 ms
4,376 KB
testcase_05 AC 2,041 ms
4,376 KB
testcase_06 AC 164 ms
4,376 KB
testcase_07 AC 165 ms
4,376 KB
testcase_08 AC 1,360 ms
4,380 KB
testcase_09 AC 1,355 ms
4,380 KB
testcase_10 AC 1,352 ms
4,380 KB
testcase_11 AC 1,353 ms
4,380 KB
testcase_12 AC 1,370 ms
4,380 KB
testcase_13 AC 2,183 ms
4,376 KB
testcase_14 AC 2,243 ms
4,376 KB
testcase_15 AC 132 ms
4,380 KB
testcase_16 AC 189 ms
4,376 KB
testcase_17 AC 306 ms
4,376 KB
testcase_18 AC 336 ms
4,376 KB
testcase_19 AC 126 ms
4,380 KB
testcase_20 AC 12 ms
4,376 KB
testcase_21 AC 138 ms
4,380 KB
testcase_22 AC 381 ms
4,380 KB
testcase_23 AC 39 ms
4,376 KB
testcase_24 AC 16 ms
4,376 KB
testcase_25 AC 639 ms
4,376 KB
testcase_26 AC 154 ms
4,376 KB
testcase_27 AC 515 ms
4,376 KB
testcase_28 AC 29 ms
4,376 KB
testcase_29 AC 467 ms
4,376 KB
testcase_30 AC 619 ms
4,380 KB
testcase_31 AC 1,766 ms
4,376 KB
testcase_32 AC 615 ms
4,376 KB
testcase_33 AC 211 ms
4,376 KB
testcase_34 AC 1,189 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0