#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e13;
#define int ll
using pii = pair<int, int>;
#define fr first
#define sc second
signed main() {
int n, q, d, a, b;
cin >> n >> q >> d >> a >> b;
//a = 1, b = d;
vector<pii> inter;
int jump = n;
for (int i = 1; i <= n; i ++) {
int x, y;
cin >> x >> y;
inter.push_back({x, y});
if (y - x + 1 >= d) {
jump = min(jump, i - 1);
}
}
int lastBefore = 0, crash = inf;
vector<pii> good;
good.push_back({0, inter[0].fr - 1});
for (int i = 0; i < jump; i ++) {
lastBefore = max(lastBefore + d, inter[i].sc + 1);
if (i < n - 1 && lastBefore >= inter[i + 1].fr) {
crash = inter[i].fr - 1;
break;
}
if (i < n - 1)
good.push_back({lastBefore, inter[i + 1].fr - 1});
else
good.push_back({lastBefore, inf});
}
crash = min(crash, jump);
for (int i = 0; i < q; i ++) {
int x;
cin >> x; //s-ar putea sa fie ocupat x
int pos = -1;
for (int pas = 1 << 20; pas; pas >>= 1)
if (pos + pas < (int)good.size() && good[pos + pas].fr <= x)
pos += pas;
if (pos != -1 && x <= good[pos].sc)
cout << x << '\n';
else
cout << -1 << '\n';
}
}
# | 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... |