結果

問題 No.1742 Binary Indexed Train
ユーザー momoyuumomoyuu
提出日時 2023-03-16 13:44:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 315 ms / 3,000 ms
コード長 846 bytes
コンパイル時間 3,449 ms
コンパイル使用メモリ 244,028 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 13:00:42
合計ジャッジ時間 10,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 249 ms
4,348 KB
testcase_04 AC 247 ms
4,348 KB
testcase_05 AC 247 ms
4,348 KB
testcase_06 AC 166 ms
4,348 KB
testcase_07 AC 165 ms
4,348 KB
testcase_08 AC 311 ms
4,348 KB
testcase_09 AC 312 ms
4,348 KB
testcase_10 AC 314 ms
4,348 KB
testcase_11 AC 313 ms
4,348 KB
testcase_12 AC 315 ms
4,348 KB
testcase_13 AC 241 ms
4,348 KB
testcase_14 AC 243 ms
4,348 KB
testcase_15 AC 65 ms
4,348 KB
testcase_16 AC 48 ms
4,348 KB
testcase_17 AC 198 ms
4,348 KB
testcase_18 AC 193 ms
4,348 KB
testcase_19 AC 104 ms
4,348 KB
testcase_20 AC 9 ms
4,348 KB
testcase_21 AC 74 ms
4,348 KB
testcase_22 AC 213 ms
4,348 KB
testcase_23 AC 15 ms
4,348 KB
testcase_24 AC 8 ms
4,348 KB
testcase_25 AC 162 ms
4,348 KB
testcase_26 AC 118 ms
4,348 KB
testcase_27 AC 145 ms
4,348 KB
testcase_28 AC 21 ms
4,348 KB
testcase_29 AC 201 ms
4,348 KB
testcase_30 AC 84 ms
4,348 KB
testcase_31 AC 239 ms
4,348 KB
testcase_32 AC 83 ms
4,348 KB
testcase_33 AC 30 ms
4,348 KB
testcase_34 AC 152 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n,q;
    cin>>n>>q;
    while(q--){
        ll s,t;
        cin>>s>>t;
        ll ans = 0;
        if(s==0){
            ll now = 1;
            while(now<=t) now <<= 1;
            now >>= 1;
            s = now;
            ans++;
        }
        //cout<<(ll)(s&-s)<<endl;
        while(true){
            //cout<<(s+s&-s)<<endl;
            if(s+(s&-s)<=t){
                ans++;
                s += s&-s;
            }else{
                break;
            }
        }
        ll now = s & (-s);
        while(s<t){
            //cout<<s<<endl;
            if(now+s<=t){
                ans++;
                s += now;
            }else{
                now >>= 1;
            }
        }
        cout<<ans<<endl;
    }
    //cout<<ans<<endl;   

}
0