This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Editor: Abdelrahman Hossam
Nickname: Blobo2_Blobo2
IOI next year isA :)
*/
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define gen(arr,n,nxt) generate(arr,arr+n,nxt)
#define base ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int mo=1e9+7;
int nxt(){int x;cin>>x;return x;}
signed main(){
base
int n=nxt(),a=nxt(),b=nxt();
a/=__gcd(a,b+1);
int x=1000000000000000001;
vector<pair<int,int> >v;
if(a<=LLONG_MAX/b)
x=a*b;
bool flag=0;
for(int i=0;i<n;i++){
int first=nxt(),sec=nxt();
if(sec-first+1>=x)flag=1;
else if(sec%x<first%x){
first%=x;
sec%=x;
v.push_back({first,x-1});
v.push_back({0,sec});
}
else v.push_back({first%x,sec%x});
}
if(flag){
cout<<x<<endl;
return 0;
}
sort(all(v));
int cnt=0,l=v[0].first,r=v[0].second;
for(int i=0;i<v.size();i++){
if(v[i].first<=r)r=max(r,v[i].second);
else{
cnt+=r-l+1;
r=v[i].second;
l=v[i].first;
}
}
cnt+=r-l+1;
cout<<cnt<<endl;
return 0;
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:46:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=0;i<v.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... |