#include <bits/stdc++.h>
using namespace std;
long long int a[200005], res[200005];
pair<long long int, int> b[200005];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long int n, m, q, c = 0;
    cin >> n >> m >> q;
    set<pair<pair<int, int>, long long int>> s;
    vector<pair<long long int, long long int>> v;
    s.insert({{1, n}, 1e18});
    for (int i = 1; i <= m; i++) {
        int l, r;
        cin >> l >> r;
        auto h = prev(s.lower_bound({{l + 1, 0}, 0}));
        auto k = *h;
        if (k.first.second >= r) {
            long long int d = k.second + l - k.first.first;
            d = c - d;
            if (d > 0) v.push_back({d, r - l + 1});
            s.erase(k);
            if (k.first.first != l) s.insert({{k.first.first, l - 1}, k.second});
            if (k.first.second != r) s.insert({{r + 1, k.first.second}, k.second});
            s.insert({{l, r}, c});
        }
        else {
            long long int d = k.second + l - k.first.first;
            d = c - d;
            if (d > 0) v.push_back({d, k.first.second - l + 1});
            s.erase(k);
            if (k.first.first != l) s.insert({{k.first.first, l - 1}, k.second});
            h = s.lower_bound({{l + 1, 0}, 0});
            vector<pair<pair<int, int>, long long int>> vv;
            while (1) {
                k = *h;
                vv.push_back(k);
                if (k.first.second >= r) {
                    d = k.second;
                    d = c + k.first.first - l - d;
                    if (d > 0) v.push_back({d, r - k.first.first + 1});
                    if (k.first.second != r) s.insert({{r + 1, k.first.second}, k.second});
                    break;
                }
                d = k.second;
                d = c + k.first.first - l - d;
                if (d > 0) v.push_back({d, k.first.second - k.first.first + 1});
                h = next(h);
            }
            for (auto w : vv) s.erase(w);
            s.insert({{l, r}, c});
        }
        c += r - l + 1;
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < q; i++) {
        cin >> b[i].first;
        b[i].second = i;
    }
    sort(b, b + q);
    c = 0;
    int j = v.size() - 1;
    for (int i = q - 1; i >= 0; i--) {
        while (j >= 0 && v[j].first > b[i].first) {
            c += v[j].second;
            j--;
        }
        res[b[i].second] = c;
    }
    for (int i = 0; i < q; i++) cout << res[i] << " ";
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |