結果
問題 |
No.1742 Binary Indexed Train
|
ユーザー |
![]() |
提出日時 | 2021-11-12 22:59:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 811 bytes |
コンパイル時間 | 3,363 ms |
コンパイル使用メモリ | 228,948 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-25 20:59:36 |
合計ジャッジ時間 | 9,438 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 22 WA * 10 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using ll=long long; using Graph=vector<vector<pair<int,ll>>>; #define INF 1000000000 #define MOD 998244353 #define MAX 300000 int main(){ int N,Q; cin>>N>>Q; for(int q=0;q<Q;q++){ ll S,T; cin>>S>>T; int ans=0; if(S+1==T){ cout<<1<<'\n'; continue; } ll left=0; ll right=1LL<<N; while(true){ ll x=(left+right)/2; if(x<S){ left=x; }else if(T<x){ right=x; }else{ break; } } ll x=(left+right)/2; ll y1=x-S; ll y2=T-x; while(y1>0){ if(y1%2==1){ ans++; } y1/=2; } while(y2>0){ if(y2%2==1){ ans++; } y2/=2; } cout<<ans<<'\n'; } }