結果
問題 |
No.1742 Binary Indexed Train
|
ユーザー |
![]() |
提出日時 | 2023-03-16 13:44:21 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 313 ms / 3,000 ms |
コード長 | 846 bytes |
コンパイル時間 | 2,860 ms |
コンパイル使用メモリ | 242,940 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-18 09:20:19 |
合計ジャッジ時間 | 9,998 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#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; }