結果
問題 | No.1742 Binary Indexed Train |
ユーザー | auaua |
提出日時 | 2021-11-12 23:14:01 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 618 ms / 3,000 ms |
コード長 | 2,083 bytes |
コンパイル時間 | 2,142 ms |
コンパイル使用メモリ | 168,420 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-08-17 03:45:59 |
合計ジャッジ時間 | 14,468 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,356 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,360 KB |
testcase_03 | AC | 571 ms
4,352 KB |
testcase_04 | AC | 582 ms
4,356 KB |
testcase_05 | AC | 578 ms
4,356 KB |
testcase_06 | AC | 194 ms
4,356 KB |
testcase_07 | AC | 189 ms
4,356 KB |
testcase_08 | AC | 618 ms
4,352 KB |
testcase_09 | AC | 618 ms
4,360 KB |
testcase_10 | AC | 612 ms
4,356 KB |
testcase_11 | AC | 614 ms
4,356 KB |
testcase_12 | AC | 614 ms
4,356 KB |
testcase_13 | AC | 565 ms
4,352 KB |
testcase_14 | AC | 570 ms
4,356 KB |
testcase_15 | AC | 107 ms
4,356 KB |
testcase_16 | AC | 91 ms
4,356 KB |
testcase_17 | AC | 302 ms
4,356 KB |
testcase_18 | AC | 308 ms
4,352 KB |
testcase_19 | AC | 144 ms
4,356 KB |
testcase_20 | AC | 14 ms
4,356 KB |
testcase_21 | AC | 119 ms
4,360 KB |
testcase_22 | AC | 344 ms
4,352 KB |
testcase_23 | AC | 26 ms
4,356 KB |
testcase_24 | AC | 12 ms
4,352 KB |
testcase_25 | AC | 311 ms
4,356 KB |
testcase_26 | AC | 170 ms
4,352 KB |
testcase_27 | AC | 275 ms
4,356 KB |
testcase_28 | AC | 29 ms
4,352 KB |
testcase_29 | AC | 344 ms
4,356 KB |
testcase_30 | AC | 191 ms
4,356 KB |
testcase_31 | AC | 537 ms
4,352 KB |
testcase_32 | AC | 184 ms
4,352 KB |
testcase_33 | AC | 65 ms
4,356 KB |
testcase_34 | AC | 345 ms
4,356 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' //#define vec vector<ll> //#define mat vector<vector<ll> > #define fi first #define se second #define double long double typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; //typedef long double ld; typedef complex<double> Complex; const ll INF=1e9+7; const ll MOD=998244353; const ll inf=INF*INF; const ll mod=MOD; const ll MAX=200010; const double PI=acos(-1.0); typedef vector<vector<ll> > mat; typedef vector<ll> vec; void solve(){ ll n,q;cin>>n>>q; vector<ll>c(n+2); c[0]=1; REP(i,1,n+2)c[i]=c[i-1]*2LL; while(q--){ ll s,t;cin>>s>>t; ll a=0,b=0; if(s){ while(s%c[a]==0){ a++; } a--; } while(t%c[b]==0){ b++; } b--; vector<ll>x(1),y(1); x[0]=s,y[0]=t; ll now=s; REP(i,a+1,n+2){ now=((now+c[i]-1LL)/c[i])*c[i]; x.pb(now); //cout<<i<<' '<<now<<endl; } now=t; REP(i,b+1,n+2){ now=(now/c[i])*c[i]; y.pb(now); //cout<<i<<' '<<now<<endl; } ll i=0,j=0; ll ans=1; while(a<b){ ans+=(x[i+1]-x[i])/c[a]; a++; i++; } while(a>b){ ans+=(y[j]-y[j+1])/c[b]; b++; j++; } while(x[i+1]<y[j+1]){ ans+=(x[i+1]-x[i])/c[a]; a++; i++; ans+=(y[j]-y[j+1])/c[b]; b++; j++; } //cout<<ans<<endl; //cout<<y[j]<<' '<<x[i]<<' '<<c[a]<<endl; if(y[j]>x[i])ans+=(y[j]-x[i])/c[a]-1; else ans--; cout<<ans<<endl; } } signed main(){ //cin.tie(0); //ios::sync_with_stdio(false); solve(); }