This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a,b;
const int inf = 2e18+5;
#define gcd(a,b) __gcd(a,b)
signed main() {
cin >> n >> a >> b;
int p;
if(a/gcd(a,b+1) > inf/b) {
p = inf;
} else {
p = a / gcd(a,b+1) * b;
}
vector<pair<int,int>> range;
for(int i = 0; i < n; i++) {
int l,r; cin >> l >> r;
if(r-l >= p) {
range.push_back({0,p-1});
} else {
l = l % p, r = r % p;
if(l > r) {
range.push_back({l, p-1});
range.push_back({0, r});
} else {
range.push_back({l,r});
}
}
}
sort(begin(range), end(range));
vector<pair<int,int>> jake;
for(auto it : range) {
if(jake.empty() or jake.back().second < it.first) {
jake.push_back(it);
} else {
jake.back().second = max(jake.back().second, it.second);
}
}
int res = 0;
for(auto it : jake) res += it.second - it.first + 1;
cout << res <<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |