/*
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,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
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 |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
6 ms |
976 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
368 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
354 ms |
17888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
490 ms |
19936 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
490 ms |
19936 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
490 ms |
19936 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
51 ms |
3984 KB |
Output is correct |
3 |
Correct |
54 ms |
3980 KB |
Output is correct |
4 |
Correct |
562 ms |
20024 KB |
Output is correct |
5 |
Correct |
52 ms |
3964 KB |
Output is correct |
6 |
Correct |
52 ms |
3928 KB |
Output is correct |
7 |
Correct |
51 ms |
3956 KB |
Output is correct |
8 |
Correct |
53 ms |
3956 KB |
Output is correct |
9 |
Correct |
52 ms |
3904 KB |
Output is correct |
10 |
Correct |
52 ms |
4004 KB |
Output is correct |
11 |
Correct |
54 ms |
4032 KB |
Output is correct |
12 |
Correct |
45 ms |
4020 KB |
Output is correct |
13 |
Correct |
52 ms |
4032 KB |
Output is correct |
14 |
Correct |
526 ms |
19976 KB |
Output is correct |
15 |
Correct |
56 ms |
3776 KB |
Output is correct |
16 |
Correct |
483 ms |
20224 KB |
Output is correct |
17 |
Correct |
475 ms |
20436 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
6 ms |
976 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |