#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long 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);
}
const llo inf = (llo)1e18 + 3;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n,a,b;
cin>>n>>a>>b;
llo x;
vector<pair<llo,llo>> it;
x=b;
llo y=a/gcd(a,b+1);
/*if(y>1000000000000000000LL/b){
}*/
/* if((b+1)%a==0){
x=b;
}
else{
x=a*b;
}*/
llo aa,bb;
llo ss=0;
vector<pair<llo,llo>> ac;
for(llo i=0;i<n;i++){
cin>>aa>>bb;
ss+=bb-aa+1;
it.pb(mp(aa,bb));
}
if(x>(llo)2*(inf/b)){
cout<<ss<<endl;
return 0;
}
x*=(a/gcd(a,b+1));
for(llo i=0;i<n;i++){
aa=it[i].ak;
bb=it[i].bk;
if(bb-aa+1>=x){
cout<<x<<endl;
return 0;
}
/*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;
}
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:95:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(llo i=0;i<prev.size();i++){
~^~~~~~~~~~~~
strange_device.cpp:26:6: warning: unused variable 'y' [-Wunused-variable]
llo y=a/gcd(a,b+1);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1012 KB |
Output is correct |
3 |
Correct |
10 ms |
1012 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
5 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 |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
252 KB |
Output is correct |
16 |
Correct |
10 ms |
1012 KB |
Output is correct |
17 |
Correct |
66 ms |
6628 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is 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 |
Correct |
5 ms |
376 KB |
Output is 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 |
Correct |
413 ms |
40828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
574 ms |
56388 KB |
Output is correct |
3 |
Correct |
581 ms |
56224 KB |
Output is correct |
4 |
Correct |
563 ms |
56348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
574 ms |
56388 KB |
Output is correct |
3 |
Correct |
581 ms |
56224 KB |
Output is correct |
4 |
Correct |
563 ms |
56348 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
575 ms |
56480 KB |
Output is correct |
7 |
Correct |
579 ms |
56480 KB |
Output is correct |
8 |
Correct |
572 ms |
56352 KB |
Output is correct |
9 |
Correct |
607 ms |
56352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
574 ms |
56388 KB |
Output is correct |
3 |
Correct |
581 ms |
56224 KB |
Output is correct |
4 |
Correct |
563 ms |
56348 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
61 ms |
6628 KB |
Output is correct |
7 |
Correct |
63 ms |
6504 KB |
Output is correct |
8 |
Correct |
59 ms |
6504 KB |
Output is correct |
9 |
Correct |
60 ms |
6636 KB |
Output is correct |
10 |
Correct |
59 ms |
6500 KB |
Output is correct |
11 |
Correct |
60 ms |
6500 KB |
Output is correct |
12 |
Correct |
62 ms |
6500 KB |
Output is correct |
13 |
Correct |
63 ms |
6500 KB |
Output is correct |
14 |
Correct |
60 ms |
6628 KB |
Output is correct |
15 |
Correct |
65 ms |
6500 KB |
Output is correct |
16 |
Correct |
65 ms |
6500 KB |
Output is correct |
17 |
Correct |
64 ms |
6628 KB |
Output is correct |
18 |
Correct |
580 ms |
56332 KB |
Output is correct |
19 |
Correct |
572 ms |
56496 KB |
Output is correct |
20 |
Correct |
623 ms |
56352 KB |
Output is correct |
21 |
Correct |
65 ms |
6500 KB |
Output is correct |
22 |
Correct |
63 ms |
6624 KB |
Output is correct |
23 |
Correct |
178 ms |
18004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
63 ms |
6500 KB |
Output is correct |
3 |
Correct |
64 ms |
6500 KB |
Output is correct |
4 |
Correct |
648 ms |
56360 KB |
Output is correct |
5 |
Correct |
50 ms |
2544 KB |
Output is correct |
6 |
Correct |
48 ms |
2540 KB |
Output is correct |
7 |
Correct |
49 ms |
2544 KB |
Output is correct |
8 |
Correct |
64 ms |
6500 KB |
Output is correct |
9 |
Correct |
62 ms |
6504 KB |
Output is correct |
10 |
Correct |
64 ms |
6532 KB |
Output is correct |
11 |
Correct |
63 ms |
6500 KB |
Output is correct |
12 |
Incorrect |
50 ms |
2544 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1012 KB |
Output is correct |
3 |
Correct |
10 ms |
1012 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
5 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 |
376 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
252 KB |
Output is correct |
16 |
Correct |
10 ms |
1012 KB |
Output is correct |
17 |
Correct |
66 ms |
6628 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
413 ms |
40828 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
574 ms |
56388 KB |
Output is correct |
31 |
Correct |
581 ms |
56224 KB |
Output is correct |
32 |
Correct |
563 ms |
56348 KB |
Output is correct |
33 |
Correct |
4 ms |
376 KB |
Output is correct |
34 |
Correct |
575 ms |
56480 KB |
Output is correct |
35 |
Correct |
579 ms |
56480 KB |
Output is correct |
36 |
Correct |
572 ms |
56352 KB |
Output is correct |
37 |
Correct |
607 ms |
56352 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
61 ms |
6628 KB |
Output is correct |
40 |
Correct |
63 ms |
6504 KB |
Output is correct |
41 |
Correct |
59 ms |
6504 KB |
Output is correct |
42 |
Correct |
60 ms |
6636 KB |
Output is correct |
43 |
Correct |
59 ms |
6500 KB |
Output is correct |
44 |
Correct |
60 ms |
6500 KB |
Output is correct |
45 |
Correct |
62 ms |
6500 KB |
Output is correct |
46 |
Correct |
63 ms |
6500 KB |
Output is correct |
47 |
Correct |
60 ms |
6628 KB |
Output is correct |
48 |
Correct |
65 ms |
6500 KB |
Output is correct |
49 |
Correct |
65 ms |
6500 KB |
Output is correct |
50 |
Correct |
64 ms |
6628 KB |
Output is correct |
51 |
Correct |
580 ms |
56332 KB |
Output is correct |
52 |
Correct |
572 ms |
56496 KB |
Output is correct |
53 |
Correct |
623 ms |
56352 KB |
Output is correct |
54 |
Correct |
65 ms |
6500 KB |
Output is correct |
55 |
Correct |
63 ms |
6624 KB |
Output is correct |
56 |
Correct |
178 ms |
18004 KB |
Output is correct |
57 |
Correct |
5 ms |
376 KB |
Output is correct |
58 |
Correct |
63 ms |
6500 KB |
Output is correct |
59 |
Correct |
64 ms |
6500 KB |
Output is correct |
60 |
Correct |
648 ms |
56360 KB |
Output is correct |
61 |
Correct |
50 ms |
2544 KB |
Output is correct |
62 |
Correct |
48 ms |
2540 KB |
Output is correct |
63 |
Correct |
49 ms |
2544 KB |
Output is correct |
64 |
Correct |
64 ms |
6500 KB |
Output is correct |
65 |
Correct |
62 ms |
6504 KB |
Output is correct |
66 |
Correct |
64 ms |
6532 KB |
Output is correct |
67 |
Correct |
63 ms |
6500 KB |
Output is correct |
68 |
Incorrect |
50 ms |
2544 KB |
Output isn't correct |
69 |
Halted |
0 ms |
0 KB |
- |