제출 #1135835

#제출 시각아이디문제언어결과실행 시간메모리
1135835adaawf이상한 기계 (APIO19_strange_device)C++20
65 / 100
441 ms78832 KiB
#include <iostream>
#include <map>
#include <vector>
#include <assert.h>
#include <algorithm>
using namespace std;
map<long long int, vector<pair<long long int, long long int>>> mm;
vector<pair<long long int, long long int>> g, gg;
long long int d[3000005], aa[1000005], bb[1000005];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    long long int n, a, b, c = 0;
    cin >> n >> a >> b;
    a = a / __gcd(a, b + 1);
    for (int i = 1; i <= n; i++) {
        long long int x, y;
        cin >> x >> y;
        aa[i] = x; bb[i] = y;
        c += y - x + 1;
    }
    if (9e18 / b < a) {
        cout << c;
        return 0;
    }
    a *= b;
    for (int i = 1; i <= n; i++) {
        long long int x = aa[i], y = bb[i];
        if (x % a <= y % a) g.push_back({x % a, y % a});
        else {
            g.push_back({x % a, a - 1});
            g.push_back({0, y % a});
        }
    }
    for (auto w : g) {
        gg.push_back({w.first, 1});
        gg.push_back({w.second + 1, -1});
    }
    sort(gg.begin(), gg.end());
    long long int res = 0;
    for (int i = 0; i < gg.size(); i++) {
        d[i + 1] = d[i] + gg[i].second;
        if (d[i + 1] > 0) res = res + (gg[i + 1].first - gg[i].first);
    }
    cout << res;
}
#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...