제출 #240344

#제출 시각아이디문제언어결과실행 시간메모리
240344valerikk이상한 기계 (APIO19_strange_device)C++14
10 / 100
5065 ms119036 KiB
#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f(i, n) for (int i = 0; i < (n); i++)

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

#define ll long long
#define ld long double
#define int long long
#define pii pair<int, int>

int ob(vector<pii> a) {
    vector<pii> v;
    for (auto s : a) {
        v.eb(s.x, 0);
        v.eb(s.y + 1, 1);
    }
    sort(all(v));
    int res = 0, cnt = 0;
    f(i, sz(v) - 1) {
        if (v[i].y == 0) cnt++; else cnt--;
        if (cnt) res += v[i + 1].x - v[i].x;
    }
    return res;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    int p = a / __gcd(a, b + 1);
    vector<int> l(n), r(n);
    f(i, n) cin >> l[i] >> r[i];
    int ans = 0;
    f(z, b) {
        vector<pii> v;
        for (int i = 0; i < n; i++) {
            if (r[i] < z) continue;
            int ql = max(0LL, (l[i] - z + b - 1) / b), qr = (r[i] - z) / b;
            if (ql <= qr) {
                ql %= p;
                qr %= p;
                if (ql <= qr) {
                    v.eb(ql, qr);
                } else {
                    v.eb(0, qr);
                    v.eb(ql, p - 1);
                }
            }
        }
        ans += ob(v);
    }
    cout << ans;
    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...