Submission #1166664

#TimeUsernameProblemLanguageResultExecution timeMemory
1166664mychecksedadTower (JOI24_tower)C++20
5 / 100
50 ms14664 KiB
/* 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];
ll DP[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 j = 0; j < N; ++j) DP[j] = 0;
  for(int i = 1; i <= n; ++i){
    cin >> P[i][0] >> P[i][1];
    for(int j = P[i][0]; j <= P[i][1]; ++j) DP[j] = -1;
  }
  DP[0] = 0;
  for(int i = 1;i  < N; ++i){
    if(DP[i] != -1){
      DP[i] = INF;
      if(DP[i - 1] != -1)
        DP[i] = DP[i - 1] + A;
      if(i - D >= 0 && DP[i - D] != -1)
        DP[i] = min(DP[i], DP[i - D] + B);
      if(DP[i] >= INF) DP[i] = -1;
    }
  }
  Q.resize(q);
  for(int i = 1; i <= q; ++i){
    cin >> Q[i-1];
    cout << DP[Q[i - 1]] << '\n';
  }
  return;
  
  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, INF-1};

  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){
      if(it != S.end()){
        last_av = it->first + D;
      }else{
        last_av = INF;
      }
    } 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 << 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...