Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define Gene template< class
- #define Rics printer& operator,
- Gene c> struct rge{c b, e;};
- Gene c> rge<c> range(c i, c j){ return {i, j};}
- struct printer{
- ~printer(){cerr<<endl;}
- Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
- Rics(string x){cerr<<x;return *this;}
- Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
- Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
- Gene c >Rics(rge<c> x){
- *this,"["; for(auto it = x.b; it != x.e; ++it)
- *this,(it==x.b?"":", "),*it; return *this,"]";}
- };
- #define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
- #define dbg(x) "[",#x,": ",(x),"] "
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- int my_rand(int l, int r) {
- return uniform_int_distribution<int>(l, r) (rng);
- }
- typedef long long LL;
- LL oddCount(LL X) {
- if(X == 0) return 0;
- LL ret = 0;
- ++X;
- for(LL k = 60; k >= 0; k--) {
- if(((X>>k)&1) == 0) {
- }
- else {
- if(k > 0) ret += (1LL<<(k-1));
- else {
- ret += __builtin_popcountll(X-1)&1;
- }
- }
- }
- return ret;
- }
- LL evenCount(LL X) {
- return (X+1)-oddCount(X);
- }
- const LL mod = 1e9+7;
- int main() {
- // freopen("in.txt", "r", stdin);
- ios::sync_with_stdio(0);
- cin.tie(0);
- int n;
- cin >> n;
- //
- // for(LL x = 1; x <= 10; x++) {
- // debug(), dbg(x), dbg(oddCount(x));
- // }
- //
- LL odd = 0, even = 0;
- LL ans = 0;
- for(int i = 0; i < n; i++) {
- LL L, R;
- cin >> L >> R;
- LL curOdd = oddCount(R) - oddCount(L-1);
- LL curEven = evenCount(R) - evenCount(L-1);
- // debug(), dbg(L), dbg(R), dbg(curOdd), dbg(curEven);
- curOdd %= mod;
- curEven %= mod;
- ans += curOdd*even%mod;
- ans %= mod;
- ans += curEven*odd%mod;
- ans %= mod;
- odd += curOdd;
- odd %= mod;
- even += curEven;
- even %= mod;
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement