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 len;
bool merged[2000100];
struct range {
int l, r;
bool operator < (range against) {
return l < against.l;
}
};
vector<range> ranges;
int gcd(int a, int b) {
if(!b)
return a;
return gcd(b, a%b);
}
signed main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
__int128_t temp = b;
temp*=a/gcd(a, b+1);
if(temp>1e18)
len = 2e18;
else
len = temp;
for(int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
if(r-l+1 >= len) {
cout << len << '\n';
return 0;
}
l%=len, r%=len;
if(l > r) {
ranges.push_back({l, len-1});
ranges.push_back({0, r});
} else {
ranges.push_back({l, r});
}
}
sort(ranges.begin(), ranges.end());
for(int i = 1; i < ranges.size(); i++) {
if(ranges[i].l <= ranges[i-1].r)
ranges[i].l = ranges[i-1].l, merged[i-1] = 1;
}
int ans = 0;
for(int i = 0; i < ranges.size(); i++)
if(!merged[i])
ans+=ranges[i].r-ranges[i].l+1;
cout << ans << '\n';
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:45:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<range>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = 1; i < ranges.size(); i++) {
| ~~^~~~~~~~~~~~~~~
strange_device.cpp:50:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<range>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0; i < ranges.size(); i++)
| ~~^~~~~~~~~~~~~~~
# | 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... |