結果
問題 | No.911 ラッキーソート |
ユーザー |
![]() |
提出日時 | 2019-10-18 21:54:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 741 ms / 2,000 ms |
コード長 | 1,814 bytes |
コンパイル時間 | 2,541 ms |
コンパイル使用メモリ | 210,648 KB |
最終ジャッジ日時 | 2025-01-07 22:50:51 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} struct FastIO{ FastIO(){ cin.tie(0); ios::sync_with_stdio(0); } }fastio_beet; //INSERT ABOVE HERE signed main(){ Int n,l,r; cin>>n>>l>>r; vector<Int> as(n); for(Int i=0;i<n;i++) cin>>as[i]; const Int MAX = 62; vector< vector<Int> > S(MAX+1); S[MAX].emplace_back(0); S[MAX].emplace_back(n); vector< set<Int> > C(MAX+1); for(Int i=MAX-1;i>=0;i--){ C[i].emplace(0); C[i].emplace(1); for(Int j=0;j+1<(Int)S[i+1].size();j++){ Int p=S[i+1][j],q=S[i+1][j+1]; S[i].emplace_back(p); vector<Int> vs(q-p); for(Int k=p;k<q;k++) vs[k-p]=(as[k]>>i)&1; if(vs==vector<Int>(q-p,0)) continue; if(vs==vector<Int>(q-p,1)) continue; auto us(vs); us.erase(unique(us.begin(),us.end()),us.end()); if(us.size()>2) drop(0); for(Int k=p;k+1<q;k++) if(vs[k-p]!=vs[k+1-p]) S[i].emplace_back(k+1); if(vs[0]==0) C[i].erase(1); if(vs[0]==1) C[i].erase(0); } S[i].emplace_back(n); //for(Int s:S[i]) cout<<s<<" "; //cout<<endl; } auto calc= [&](Int k)->Int{ vector<Int> dp(2,0); dp[1]=1; for(Int i=MAX-1;i>=0;i--){ Int b=(k>>i)&1; vector<Int> nx(2,0); for(Int c:C[i]){ for(Int t=0;t<2;t++){ if(t&&c>b) continue; Int nt=t&&(b==c); nx[nt]+=dp[t]; } } swap(dp,nx); } return dp[0]+dp[1]; }; Int ans=calc(r); if(l) ans-=calc(l-1); cout<<ans<<endl; return 0; }