제출 #1173296

#제출 시각아이디문제언어결과실행 시간메모리
1173296thinknoexit이상한 기계 (APIO19_strange_device)C++20
10 / 100
430 ms33368 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18 + 2;
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    ll A, B;
    cin >> n >> A >> B;
    // B++;
    ll one = A;
    if (one >= (INF + B - 1) / B) one = INF;
    else one *= B;
    // cout << one << '\n';
    vector<pair<ll, int>> sweep;
    for (int i = 1;i <= n;i++) {
        ll l, r;
        cin >> l >> r;
        if (r - l + 1 >= one) {
            cout << one << '\n';
            return 0;
        }
        l %= one, r %= one;
        // cout << l << ' ' << r << '\n';
        if (l <= r) {
            sweep.push_back({ l, 1 });
            sweep.push_back({ r + 1, -1 });
        }
        else {
            sweep.push_back({ 0, 1 });
            sweep.push_back({ r + 1, -1 });
            sweep.push_back({ l, 1 });
            sweep.push_back({ one, -1 });
        }
    }
    sort(sweep.begin(), sweep.end());
    ll ans = 0;
    int now = 0;
    for (int i = 0, j;i < (int)sweep.size();i = j) {
        for (j = i;j < (int)sweep.size() && sweep[i].first == sweep[j].first; j++) {
            now += sweep[j].second;
        }
        if (now > 0) {
            ans += sweep[j].first - sweep[i].first;
        }
    }
    cout << ans << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...