Submission #554213

#TimeUsernameProblemLanguageResultExecution timeMemory
554213happypotato이상한 기계 (APIO19_strange_device)C++17
0 / 100
1494 ms68924 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    if (b >= 3e18 / a) {
        int ans = 0;
        while (n--) {
            int l, r;
            cin >> l >> r;
            ans += r - l + 1;
        }
        cout << ans << endl;
        return;
    }
    priority_queue<pair<int, bool>, vector<pair<int, bool> >, greater<pair<int, bool> > > pq;
    int mod = a * b;
    while (n--) {
        int l, r;
        cin >> l >> r;
        l %= mod; r %= mod;
        if (l > r) swap(l, r);
        pq.push({l, true});
        pq.push({r + 1, false});
    }
    int prev = 0, ans = 0;
    int cnt = 0;
    while (!pq.empty()) {
        pair<int, bool> cur = pq.top();
        pq.pop();
        if (cnt) ans += cur.first - prev;
        prev = cur.first;
        cnt += (cur.second ? 1 : -1);
    }
    cout << ans << endl;
}
signed main() {
    solve();
}
#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...