Advertisement
Dang_Quan_10_Tin

CONES

Mar 15th, 2022
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #define task "CONES"
  2. #include <iostream>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. constexpr int N = 1e5 + 5;
  11.  
  12. int n, q;
  13.  
  14. void Read()
  15. {
  16.     cin >> n >> q;
  17. }
  18.  
  19. ll Get(ll n, ll k)
  20. {
  21.     if (k <= n)
  22.         return k;
  23.  
  24.     ll ans = 0, len = 0;
  25.     k -= n;
  26.  
  27.     for (int i = 0; i < n; ++i)
  28.         if (len * 2 + i + 1 > k)
  29.         {
  30.             ans += Get(i + 1, k - len);
  31.             break;
  32.         }
  33.         else
  34.         {
  35.             ans = ans * 2 + len + i + 1;
  36.             len = len * 2 + i + 1;
  37.         }
  38.  
  39.     return ans + k + n;
  40. }
  41.  
  42. void Solve()
  43. {
  44.     while (q--)
  45.     {
  46.         ll x, y;
  47.         cin >> x >> y;
  48.  
  49.         cout << Get(n, y) - Get(n, x - 1) << "\n";
  50.     }
  51. }
  52.  
  53. int32_t main()
  54. {
  55.     ios_base::sync_with_stdio(0);
  56.     cin.tie(0);
  57.     cout.tie(0);
  58.  
  59.     if (fopen(task ".INP", "r"))
  60.     {
  61.         freopen(task ".INP", "r", stdin);
  62.         freopen(task ".OUT", "w", stdout);
  63.     }
  64.  
  65.     Read();
  66.     Solve();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement