Submission #1207934

#TimeUsernameProblemLanguageResultExecution timeMemory
1207934onbertTower (JOI24_tower)C++20
25 / 100
84 ms8624 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 5, INF = 1e15;
int n, q, d, a, b;
vector<pair<int,int>> block, space;
vector<int> qry;

int belong(int i) {
    int id = lower_bound(block.begin(), block.end(), make_pair(i+1, -INF)) - block.begin() - 1;
    if (id >= 0 && i <= block[id].second) return id;
    else return -1;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> q >> d >> a >> b;
    n++;
    vector<pair<int,int>> vec(n);
    vec[0] = {-(d-1), -1};
    for (int i=1;i<n;i++) cin >> vec[i].first >> vec[i].second;
    for (int i=0;i<n;i++) {
        auto [l, r] = vec[i];
        if (block.size()) {
            if (r <= block.back().second) continue;
            else if (l - 1 <= block.back().second) {
                l = block.back().first;
                block.pop_back();
            }
        }
        if ((r+1) - (l-1) > d) r = INF;
        else {
            int id = belong(r+1 - d);
            if (id != -1) r = block[id].second + d;
        }
        block.push_back({l, r});
        // cout << i << " " << l << " " << r << endl;
    }
    n = block.size();
    // for (auto [l, r]:vec) cout << l << " " << r << endl;

    while (q--) {
        int x;
        cin >> x;
        // cout << belong(x) << endl;
        if (belong(x) == -1) cout << x << "\n";
        else cout << "-1\n";
    }

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...