/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
const ll INF = 1e13;
int n, q;
ll D, A, B;
array<ll, 2> P[N], U[N];
vector<ll> Q;
map<ll, ll> ans;
set<pair<ll, ll>> S;
ll get(ll x){
auto it = S.lower_bound(pii{x, INF});
if(it == S.begin() || prev(it)->second < x){
assert(false);
}
return ans[prev(it)->first] + (x - prev(it)->first) * A;
}
void solve(){
cin >> n >> q >> D >> A >> B;
for(int i = 1; i <= n; ++i){
cin >> P[i][0] >> P[i][1];
}
Q.resize(q);
for(int i = 1; i <= q; ++i){
cin >> Q[i-1];
}
sort(P+1, P+1+n);
ans[0] = 0;
ll lst = 0;
for(int i = 1; i <= n; ++i){
U[i] = {lst, P[i][0] - 1};
lst = P[i][1] + 1;
}
U[n + 1] = array<ll, 2>{lst, (ll)(1e12*1ll)};
S.insert(pair<ll,ll>{U[1][0], U[1][1]});
for(int i = 2; i <= n + 1; ++i){
auto it = S.lower_bound(pii{U[i][0] - D, INF});
ll last_av = -1;
if(it == S.begin() || prev(it)->second < U[i][0] - D){
last_av = it->first + D;
} else{
last_av = U[i][0];
}
if(last_av <= U[i][1]){
ans[last_av] = get(last_av - D) + B;
S.insert({last_av, U[i][1]});
}
}
// for(auto [x,y]: S) cout << x << ' ' << y << '\n';
// for(auto [x,y]: S) cout << ans[x] << '\n';
for(int i = 1; i <= q; ++i){
ll X = Q[i - 1];
auto it = S.lower_bound(pii{X, INF});
if(it == S.begin() || prev(it)->second < X){
cout << "-1\n";
}else{
cout << get(X) << '\n';
}
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
# | 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... |