func_code_string: #include <bits/stdc++.h>   int p;   struct seg {     std::vector<int64_t> cuts;     int64_t sum;     int64_t operator()(int64_t x) const {       return x + sum -              p * int64_t(std::upper_bound(begin(cuts), end(cuts), x) -                          begin(cuts));     }   };   seg operator*(seg const& a, seg const& b) {     for (unsigned i = 1; i < a.cuts.size(); ++i)       assert(a.cuts[i] - a.cuts[i - 1] >= p);     for (unsigned i = 1; i < b.cuts.size(); ++i)       assert(b.cuts[i] - b.cuts[i - 1] >= p);     seg out;     out.sum = a.sum + b.sum;     out.cuts.reserve(a.cuts.size() + b.cuts.size());     int64_t x = INT64_MIN / 2;     auto iter1 = begin(a.cuts);     auto iter2 = begin(b.cuts);     while (true) {       auto x1 = x + a.sum - p * int64_t(iter1 - begin(a.cuts));       auto x2 = x1 + b.sum - p * int64_t(iter2 - begin(b.cuts));       assert(iter1 == std::upper_bound(begin(a.cuts), end(a.cuts), x));       assert(a(x) == x1);       assert(iter2 == std::upper_bound(begin(b.cuts), end(b.cuts), x1));       assert(b(x1) == x2);       auto d1 = iter1 == end(a.cuts) ? INT64_MAX : *iter1 - x;       auto d2 = iter2 == end(b.cuts) ? INT64_MAX : *iter2 - x1;       assert(d1 > 0);       assert(d2 > 0);       if (d1 != INT64_MAX)         assert(iter1 != std::upper_bound(begin(a.cuts), end(a.cuts), x + d1));       if (d2 < d1) {         assert(iter1 == std::upper_bound(begin(a.cuts), end(a.cuts), x + d2));         assert(a(x + d2) == x1 + d2);         assert(iter2 != std::upper_bound(begin(b.cuts), end(b.cuts), x1 + d2));         x += d2;         out.cuts.push_back(x);         ++iter2;       } else if (d1 == INT64_MAX) {         break;       } else {         x += d1;         ++iter1;         auto new_x1 = x1 + d1 - p;         assert(a(x) == new_x1);         assert(std::upper_bound(begin(b.cuts), end(b.cuts), new_x1) <= iter2);         if (iter2 != begin(b.cuts) and iter2[-1] > new_x1) {           --iter2;           assert(std::upper_bound(begin(b.cuts), end(b.cuts), new_x1) == iter2);         } else {           out.cuts.push_back(x);         }       }     }     assert(out.cuts.size() == a.cuts.size() + b.cuts.size());     return out;   }   std::vector<seg> st;   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     int n, nquery;     std::cin >> n >> nquery >> p;     st.resize(n * 2);     for (int i = n; i < 2 * n; ++i) {       int ai;       std::cin >> ai;       st[i].cuts.push_back(p - ai);       st[i].sum = ai;     }     for (int i = n; --i;) st[i] = st[i << 1] * st[i << 1 | 1];     while (nquery--) {       int l, r;       std::cin >> l >> r;       --l;       l += n;       r += n;       int64_t out = 0;       std::vector<seg*> pendr;       while (l < r) {         if (l & 1) out = st[l++](out);         if (r & 1) pendr.push_back(&(st[--r]));         l >>= 1;         r >>= 1;       }       while (not pendr.empty()) {         out = (*pendr.back())(out);         pendr.pop_back();       }       std::cout << out <<   n ;     }   }   