Advertisement
_ash__

Untitled

Dec 10th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define Gene template< class
  5. #define Rics printer& operator,
  6. Gene c> struct rge{c b, e;};
  7. Gene c> rge<c> range(c i, c j){ return {i, j};}
  8. struct printer{
  9. ~printer(){cerr<<endl;}
  10. Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
  11. Rics(string x){cerr<<x;return *this;}
  12. Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
  13. Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
  14. Gene c >Rics(rge<c> x){
  15. *this,"["; for(auto it = x.b; it != x.e; ++it)
  16. *this,(it==x.b?"":", "),*it; return *this,"]";}
  17. };
  18. #define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
  19. #define dbg(x) "[",#x,": ",(x),"] "
  20. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  21. int my_rand(int l, int r) {
  22. return uniform_int_distribution<int>(l, r) (rng);
  23. }
  24.  
  25. typedef long long LL;
  26.  
  27. LL oddCount(LL X) {
  28. if(X == 0) return 0;
  29. LL ret = 0;
  30. ++X;
  31. for(LL k = 60; k >= 0; k--) {
  32. if(((X>>k)&1) == 0) {
  33.  
  34. }
  35. else {
  36. if(k > 0) ret += (1LL<<(k-1));
  37. else {
  38. ret += __builtin_popcountll(X-1)&1;
  39. }
  40. }
  41. }
  42. return ret;
  43. }
  44.  
  45. LL evenCount(LL X) {
  46. return (X+1)-oddCount(X);
  47. }
  48.  
  49. const LL mod = 1e9+7;
  50.  
  51. int main() {
  52. // freopen("in.txt", "r", stdin);
  53. ios::sync_with_stdio(0);
  54. cin.tie(0);
  55.  
  56. int n;
  57. cin >> n;
  58. //
  59. // for(LL x = 1; x <= 10; x++) {
  60. // debug(), dbg(x), dbg(oddCount(x));
  61. // }
  62. //
  63.  
  64.  
  65. LL odd = 0, even = 0;
  66. LL ans = 0;
  67. for(int i = 0; i < n; i++) {
  68. LL L, R;
  69. cin >> L >> R;
  70.  
  71. LL curOdd = oddCount(R) - oddCount(L-1);
  72. LL curEven = evenCount(R) - evenCount(L-1);
  73.  
  74. // debug(), dbg(L), dbg(R), dbg(curOdd), dbg(curEven);
  75.  
  76. curOdd %= mod;
  77. curEven %= mod;
  78.  
  79. ans += curOdd*even%mod;
  80. ans %= mod;
  81.  
  82. ans += curEven*odd%mod;
  83. ans %= mod;
  84.  
  85. odd += curOdd;
  86. odd %= mod;
  87. even += curEven;
  88. even %= mod;
  89.  
  90. }
  91.  
  92. cout << ans << endl;
  93. }
  94.  
  95.  
  96.  
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement