This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 34 days to apio!
#include <bits/stdc++.h>
using namespace std;
#define int long long
main() {
int n, a, b, p; cin >> n >> a >> b;
a /= __gcd(a,b+1);
if(a>1e18/b) p=1e18;
else p=a * b;
vector<pair<int,int>> v;
for(int i=0;i<n;i++) {
int l, r; cin >> l >> r;
if(r-l>p) {cout<<p; return 0;}
else if(l/p == r/p) v.push_back({l%p,r%p});
else {
v.push_back({l%p,p-1});
v.push_back({0,r%p});
}
}
sort(v.begin(),v.end(),greater<pair<int,int>>());
int ans = 0;
while(v.size()>=2) {
if(end(v)[-2].first<=end(v)[-1].second) end(v)[-2]={end(v)[-1].first,max(end(v)[-1].second,end(v)[-2].second)};
else ans += end(v)[-1].second-end(v)[-1].first+1;
v.pop_back();
}
cout << ans + v[0].second - v[0].first + 1;
}
Compilation message (stderr)
strange_device.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
5 | main() {
| ^~~~
# | 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... |