Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define int long long
- #define mp make_pair
- #define pb push_back
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC target("avx2")
- typedef long long ll;
- constexpr int N = (int)5e5 + 111;
- constexpr ll INF = (ll)1e18;
- constexpr int md = (int)1e9+7;
- void add(int& a,int b){
- a = a + b;
- // a = (a+b >= md ? a+b-md : a+b);
- }
- void sub(ll& a,ll b){
- a = (a-b < 0 ? a-b+md : a-b);
- }
- mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
- int bpow(int a,int b){
- if(b == 0)
- return 1;
- if(b % 2 == 0){
- int t = bpow(a,b>>1);
- return t * t % md;
- }
- return a * bpow(a,b-1) % md;
- }
- void solve(){
- int n;
- cin >> n;
- int l,r;
- cin >> l >> r;
- int ans = 0;
- int dp[2][60][2][2];
- bool Set = false;
- for(int first = 59; first >= 0; first--){
- if((1ll << first) > n)
- continue;
- memset(dp,0,sizeof dp);
- dp[0][1][1][((n >> first & 1) == 0) || Set] = 1;
- Set |= (n >> first & 1);
- for(int j = first-1; j >= 0; j--){
- for(int bt = 0; bt < 2; bt++){
- for(int len = 1; len <= r; len++){
- for(int pr = 0; pr < 2; pr++){
- for(int Less = 0; Less < 2; Less++){
- if(!Less && (n >> j & 1) < bt)
- continue;
- if(bt != pr){
- int nwLess = Less || ((n >> j & 1) > bt);
- if(l <= len)
- add(dp[1][1][bt][nwLess],dp[0][len][pr][Less]);
- } else {
- int nwLen = len + 1;
- int nwLess = Less || ((n >> j & 1) > bt);
- if(nwLen <= r)
- add(dp[1][nwLen][bt][nwLess],dp[0][len][pr][Less]);
- }
- }
- }
- }
- }
- for(int len = 1; len <= r; len++){
- for(int bt = 0; bt < 2; bt++){
- for(int Less = 0; Less < 2; Less++){
- dp[0][len][bt][Less] = dp[1][len][bt][Less];
- dp[1][len][bt][Less] = 0;
- }
- }
- }
- }
- int sum = 0;
- for(int len = l; len <= r; len++){
- for(int bt = 0; bt < 2; bt++){
- for(int Less = 0; Less < 2; Less++){
- add(ans,dp[0][len][bt][Less]);
- add(sum,dp[0][len][bt][Less]);
- }
- }
- }
- }
- cout << ans << "\n";
- return;
- }
- signed main(){
- ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr);
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- int tests = 1;
- // cin >> tests;
- for(int test = 1; test <= tests; test++){
- solve();
- }
- return 0;
- }
- /**
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement