結果

問題 No.1742 Binary Indexed Train
コンテスト
ユーザー Shirotsume
提出日時 2021-10-22 20:15:57
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 167 ms / 3,000 ms
コード長 538 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 518 ms
コンパイル使用メモリ 80,660 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-06-23 10:23:58
合計ジャッジ時間 4,999 ms
ジャッジサーバーID
(参考情報)
<nil> / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
using namespace std;

int solve(long long int s, long long int t, long long int n){
    long long int k = (long long int)1 << n;
    while (((t - 1) / k <= (s - 1) / k)){
        k = k >> 1;
    }
    long long int mid = k * ((s+k-1)/k);
    return __builtin_popcountll(mid - s) + __builtin_popcountll(t - mid);
}
int main(void){
    int n, q;

    cin >> n >> q;
    
    for(int i = 0; i < q; i++){
        long long int s, t;
        cin >> s >> t;
        cout << solve(s, t, n) << endl;
    }
    
    return 0;
}
0