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();
int x=a*b;
vector<pair<int,int> >v;
if(a!=x/b)
for(int i=0;i<n;i++)
v.push_back({nxt(),nxt()});
else{
bool flag=0;
for(int i=0;i<n;i++){
int first=nxt(),sec=nxt();
if(sec-first==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,now=-1;
for(int i=0;i<v.size();i++){
if(now==-1){
now=v[i].second+1;
cnt+=v[i].second-v[i].first+1;
}
else if(now>=v[i].second)
continue;
else if(now<v[i].first){
cnt+=v[i].second-v[i].first+1;
now=v[i].second+1;
}
else if(now>=v[i].first){
cnt+=v[i].second-now+1;
now=v[i].second+1;
}
}
cout<<cnt<<endl;
return 0;
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:48: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]
48 | 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... |