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;
void bruh(int n){
long long int ans=0;
for(int i=0;i<n;i++){
long long int l,r;
cin >> l >> r;
ans+=(r-l+1);
}
cout << ans << endl;
return;
}
int main(){
long long int n,a,b;
cin >> n >> a >> b;
long long int x=a/gcd(a,b+1);
if(b<1e18*1.0/x){
x*=b;
}
else{
bruh(n);
return 0;
}
vector<pair<long long int,long long int>> ranges;
for(int i=0;i<n;i++){
long long int l,r;
cin >> l >> r;
if(r-l+1>=x){
cout << x << endl;
return 0;
}
l%=x;
r%=x;
if(l<=r){
ranges.push_back({l,r});
}
else{
ranges.push_back({0,r});
ranges.push_back({l,x-1});
}
}
sort(ranges.begin(),ranges.end());
long long int curl=ranges[0].first,curr=ranges[0].second,ans=0;
for(int i=1;i<ranges.size();i++){
pair<long long int,long long int> range=ranges[i];
if(curr<range.first){
ans+=(curr-curl+1);
curl=range.first;
curr=range.second;
}
else{
curr=max(curr,range.second);
}
}
ans+=(curr-curl+1);
cout << ans << endl;
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=1;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... |