Submission #1102098

# Submission time Handle Problem Language Result Execution time Memory
1102098 2024-10-17T12:19:34 Z Pacybwoah Tower (JOI24_tower) C++17
0 / 100
1242 ms 2188 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<cassert>
#include<set>
using namespace std;
typedef long long ll;
ll inf = 8e18;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    ll d, a, b;
    cin >> d >> a >> b;
    vector<pair<ll, ll>> vec, free;
    for(int i = 0; i < n; i++){
        ll l, r;
        cin >> l >> r;
        vec.emplace_back(l, r);
        if(i == 0) free.emplace_back(0, l - 1);
        else free.emplace_back(vec[i - 1].second + 1, l - 1);
    }
    free.emplace_back(vec[n - 1].second + 1, inf);
    set<pair<ll, ll>> s, sq;
    vector<pair<ll, ll>> fq;
    for(auto &[l, r]: free){
        ll fst = r + 1;
        if(l == 0) fst = 0;
        else{
            auto iter = s.lower_bound(make_pair(l, -1));
            if(iter != s.end()){
                if((*iter).first <= r) fst = (*iter).first;
            }
            if(iter != s.begin()){
                iter = prev(iter);
                if((*iter).second >= l) fst = l;
            }
        }
        if(fst <= r) s.emplace(fst + d, r + d), sq.emplace(fst, r), fq.emplace_back(fst, r);
    }
    reverse(fq.begin(), fq.end());
    for(int i = 0; i < q; i++){
        ll x;
        cin >> x;
        ll ori = x;
        auto iter = sq.lower_bound(make_pair(x + 1, 0));
        if(iter == sq.begin()){
            cout << "-1\n";
            continue;
        }
        iter = prev(iter);
        if((*iter).second < x){
            cout << "-1\n";
            continue;
        }
        if(d * a <= b){
            ll cnt = 0;
            while(x > 0){
                iter = prev(sq.lower_bound(make_pair(x + 1, 0)));
                if((*iter).first == 0){
                    break;
                }
                x = (*iter).first - d;
                cnt++;
            }
            cout << (ori - cnt * d) * a + cnt * b;
        }
        else{
            ll cnt = 0;
            /*while(x >= d){
                iter = prev(sq.lower_bound(make_pair(x + 1, 0)));
                //cout << (*iter).first << " " << (*iter).second << "\n";
                cnt += (x - (*iter).first) / d;
                x = (*iter).first + (x - (*iter).first) % d;
                if(x < d) break;
                x -= d;
                iter = prev(sq.lower_bound(make_pair(x + 1, 0)));
                if((*iter).second < x) x = (*iter).second;
                cnt++;
                //cout << cnt << "\n";
                //cout << x << "\n";
            }
            cout << (ori - cnt * d) * a + cnt * b << "\n";
            //cout << cnt << "\n";*/
            int sz = fq.size();
            for(int j = 0; j < sz; j++){
                auto &[l, r] = fq[j];
                //cout << l << " " << r << " " << cnt << "\n";
                if(l > x) continue;
                if(r < x) x = r;
                cnt += (x - l) / d;
                x = l + (x - l) % d;
                if(j < sz - 1){
                    cnt++;
                    x -= d;
                }
            }
            cout << (ori - cnt * d) * a + cnt * b << "\n";
        }
    }
    /*for(auto &[l, r]: free){
        cout << l << " " << r << "\n";
    }*/
}
// g++ -std=c++17 -Wall -Wextra -Wshadow -fsanitize=undefined -fsanitize=address -o run tower.cpp
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 329 ms 2188 KB Output is correct
4 Correct 363 ms 2120 KB Output is correct
5 Incorrect 1242 ms 2076 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 5 ms 592 KB Output is correct
4 Correct 6 ms 592 KB Output is correct
5 Incorrect 16 ms 760 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 329 ms 2188 KB Output is correct
4 Correct 363 ms 2120 KB Output is correct
5 Incorrect 1242 ms 2076 KB Output isn't correct
6 Halted 0 ms 0 KB -