Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "CONES"
- #include <iostream>
- #include <cstdio>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 1e5 + 5;
- int n, q;
- void Read()
- {
- cin >> n >> q;
- }
- ll Get(ll n, ll k)
- {
- if (k <= n)
- return k;
- ll ans = 0, len = 0;
- k -= n;
- for (int i = 0; i < n; ++i)
- if (len * 2 + i + 1 > k)
- {
- ans += Get(i + 1, k - len);
- break;
- }
- else
- {
- ans = ans * 2 + len + i + 1;
- len = len * 2 + i + 1;
- }
- return ans + k + n;
- }
- void Solve()
- {
- while (q--)
- {
- ll x, y;
- cin >> x >> y;
- cout << Get(n, y) - Get(n, x - 1) << "\n";
- }
- }
- int32_t main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement