#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef int64_t llo;
#define a first
#define b 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;
set<pair<llo,llo>> ac;
for(llo i=0;i<n;i++){
cin>>aa>>bb;
if(bb-aa+1>=x){
cout<<x<<endl;
return 0;
}
aa%=x;
bb%=x;
if(bb<aa){
ac.insert(mp(aa,x-1));
ac.insert(mp(0,bb));
}
else{
ac.insert(mp(aa,bb));
}
}
vector<pair<llo,llo>> prev;
for(auto cc:ac){
if(prev.size()==0){
prev.pb(cc);
}
else{
if(cc.a>prev.back().b){
prev.pb(cc);
}
else{
prev[prev.size()-1].b=max(prev[prev.size()-1].b,cc.b);
}
}
}
llo tot=0;
for(llo i=0;i<prev.size();i++){
tot+=prev[i].b-prev[i].a+1;
}
cout<<tot<<endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:67:15: 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 |
13 ms |
1400 KB |
Output is correct |
3 |
Correct |
12 ms |
1400 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
352 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 |
376 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 |
12 ms |
1400 KB |
Output is correct |
17 |
Correct |
82 ms |
8804 KB |
Output is correct |
18 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
4 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 |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
368 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
780 ms |
79568 KB |
Output is correct |
3 |
Correct |
790 ms |
79568 KB |
Output is correct |
4 |
Correct |
823 ms |
79696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
780 ms |
79568 KB |
Output is correct |
3 |
Correct |
790 ms |
79568 KB |
Output is correct |
4 |
Correct |
823 ms |
79696 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
803 ms |
79568 KB |
Output is correct |
7 |
Correct |
817 ms |
79696 KB |
Output is correct |
8 |
Correct |
813 ms |
79596 KB |
Output is correct |
9 |
Correct |
864 ms |
79568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
780 ms |
79568 KB |
Output is correct |
3 |
Correct |
790 ms |
79568 KB |
Output is correct |
4 |
Correct |
823 ms |
79696 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
76 ms |
8812 KB |
Output is correct |
7 |
Correct |
79 ms |
8812 KB |
Output is correct |
8 |
Correct |
81 ms |
8808 KB |
Output is correct |
9 |
Correct |
85 ms |
8812 KB |
Output is correct |
10 |
Correct |
78 ms |
8812 KB |
Output is correct |
11 |
Correct |
86 ms |
8940 KB |
Output is correct |
12 |
Correct |
85 ms |
8808 KB |
Output is correct |
13 |
Correct |
83 ms |
8812 KB |
Output is correct |
14 |
Correct |
79 ms |
8808 KB |
Output is correct |
15 |
Correct |
86 ms |
8812 KB |
Output is correct |
16 |
Correct |
86 ms |
8936 KB |
Output is correct |
17 |
Correct |
80 ms |
8812 KB |
Output is correct |
18 |
Correct |
797 ms |
79696 KB |
Output is correct |
19 |
Correct |
802 ms |
79744 KB |
Output is correct |
20 |
Correct |
833 ms |
79568 KB |
Output is correct |
21 |
Correct |
81 ms |
8812 KB |
Output is correct |
22 |
Correct |
84 ms |
8808 KB |
Output is correct |
23 |
Correct |
154 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
90 ms |
9068 KB |
Output is correct |
3 |
Correct |
82 ms |
8812 KB |
Output is correct |
4 |
Correct |
831 ms |
79824 KB |
Output is correct |
5 |
Correct |
85 ms |
8808 KB |
Output is correct |
6 |
Correct |
86 ms |
8808 KB |
Output is correct |
7 |
Correct |
87 ms |
8808 KB |
Output is correct |
8 |
Correct |
83 ms |
8808 KB |
Output is correct |
9 |
Correct |
84 ms |
8812 KB |
Output is correct |
10 |
Correct |
83 ms |
8812 KB |
Output is correct |
11 |
Correct |
82 ms |
8812 KB |
Output is correct |
12 |
Correct |
83 ms |
8812 KB |
Output is correct |
13 |
Correct |
91 ms |
8812 KB |
Output is correct |
14 |
Correct |
828 ms |
79696 KB |
Output is correct |
15 |
Correct |
79 ms |
8812 KB |
Output is correct |
16 |
Correct |
805 ms |
79568 KB |
Output is correct |
17 |
Correct |
789 ms |
79568 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 |
13 ms |
1400 KB |
Output is correct |
3 |
Correct |
12 ms |
1400 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
352 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 |
376 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 |
12 ms |
1400 KB |
Output is correct |
17 |
Correct |
82 ms |
8804 KB |
Output is correct |
18 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |