#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef int64_t llo;
#define ak first
#define bk second
#define endl "\n"
llo gcd(llo kk,llo ll){
if(ll==0){
return kk;
}
return gcd(ll,kk%ll);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n,a,b;
cin>>n>>a>>b;
llo x;
pair<llo,llo> it;
x=b;
x*=(a/gcd(a,b+1));
/* if((b+1)%a==0){
x=b;
}
else{
x=a*b;
}*/
llo aa,bb;
llo s=0;
vector<pair<llo,llo>> ac;
for(llo i=0;i<n;i++){
cin>>aa>>bb;
if(bb-aa+1>=x){
s=1;
continue;
}
/*if(bb-aa+1>=x){
ac.pb(mp(0,x-1));
}*/
aa%=x;
bb%=x;
if(bb<aa){
ac.pb(mp(aa,x-1));
ac.pb(mp(0,bb));
}
else{
ac.pb(mp(aa,bb));
}
}
if(s==1){
cout<<x<<endl;
return 0;
}
/* if(s==1){
cout<<x<<endl;
}
else{*/
vector<pair<llo,llo>> prev;
sort(ac.begin(),ac.end());
for(auto cc:ac){
if(prev.size()==0){
prev.pb(cc);
}
else{
if(cc.ak>prev[prev.size()-1].bk){
prev.pb(cc);
}
else{
prev[prev.size()-1].bk=max(prev[prev.size()-1].bk,cc.bk);
}
}
}
llo tot=0;
for(llo i=0;i<prev.size();i++){
tot+=prev[i].bk-prev[i].ak+1;
}
/* if(s==1 and tot<x){
while(true){
int y=1;
}
}
*/
cout<<tot<<endl;
//}
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:81:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(llo i=0;i<prev.size();i++){
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
888 KB |
Output is correct |
3 |
Correct |
10 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
380 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
888 KB |
Output is correct |
17 |
Correct |
72 ms |
4968 KB |
Output is correct |
18 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
414 ms |
16852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
629 ms |
40648 KB |
Output is correct |
3 |
Correct |
584 ms |
40640 KB |
Output is correct |
4 |
Correct |
550 ms |
40640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
629 ms |
40648 KB |
Output is correct |
3 |
Correct |
584 ms |
40640 KB |
Output is correct |
4 |
Correct |
550 ms |
40640 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
559 ms |
40712 KB |
Output is correct |
7 |
Correct |
563 ms |
40636 KB |
Output is correct |
8 |
Correct |
546 ms |
40644 KB |
Output is correct |
9 |
Correct |
600 ms |
40780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
629 ms |
40648 KB |
Output is correct |
3 |
Correct |
584 ms |
40640 KB |
Output is correct |
4 |
Correct |
550 ms |
40640 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
59 ms |
4968 KB |
Output is correct |
7 |
Correct |
68 ms |
4972 KB |
Output is correct |
8 |
Correct |
63 ms |
4968 KB |
Output is correct |
9 |
Correct |
61 ms |
5152 KB |
Output is correct |
10 |
Correct |
59 ms |
4972 KB |
Output is correct |
11 |
Correct |
60 ms |
4968 KB |
Output is correct |
12 |
Correct |
57 ms |
4968 KB |
Output is correct |
13 |
Correct |
62 ms |
5092 KB |
Output is correct |
14 |
Correct |
60 ms |
4968 KB |
Output is correct |
15 |
Correct |
63 ms |
4968 KB |
Output is correct |
16 |
Correct |
59 ms |
4968 KB |
Output is correct |
17 |
Correct |
66 ms |
4968 KB |
Output is correct |
18 |
Correct |
546 ms |
40620 KB |
Output is correct |
19 |
Correct |
547 ms |
40640 KB |
Output is correct |
20 |
Correct |
632 ms |
40640 KB |
Output is correct |
21 |
Correct |
62 ms |
4968 KB |
Output is correct |
22 |
Correct |
57 ms |
4968 KB |
Output is correct |
23 |
Correct |
175 ms |
8672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
62 ms |
4968 KB |
Output is correct |
3 |
Correct |
64 ms |
4972 KB |
Output is correct |
4 |
Correct |
648 ms |
40736 KB |
Output is correct |
5 |
Correct |
65 ms |
4972 KB |
Output is correct |
6 |
Correct |
61 ms |
4932 KB |
Output is correct |
7 |
Correct |
90 ms |
4968 KB |
Output is correct |
8 |
Correct |
61 ms |
4968 KB |
Output is correct |
9 |
Correct |
58 ms |
4968 KB |
Output is correct |
10 |
Correct |
61 ms |
4972 KB |
Output is correct |
11 |
Correct |
60 ms |
4976 KB |
Output is correct |
12 |
Correct |
57 ms |
4968 KB |
Output is correct |
13 |
Correct |
71 ms |
5248 KB |
Output is correct |
14 |
Correct |
603 ms |
40764 KB |
Output is correct |
15 |
Correct |
59 ms |
4968 KB |
Output is correct |
16 |
Correct |
554 ms |
40616 KB |
Output is correct |
17 |
Correct |
550 ms |
40700 KB |
Output is correct |
18 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
888 KB |
Output is correct |
3 |
Correct |
10 ms |
888 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
380 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
888 KB |
Output is correct |
17 |
Correct |
72 ms |
4968 KB |
Output is correct |
18 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |