#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int inf=1e18+5;
int32_t main(){
int n,a,b;
cin>>n>>a>>b;
int x;
if(inf/b<a/__gcd(a,b+1)){
x=inf;
}
else x=b*(a/__gcd(a,b+1));
vector<pair<int,int>>pre;
for(int i=0;i<n;i++){
int l,r;
cin>>l>>r;
if(r-l+1>=x){
cout<<x<<endl;
return 0;
}
if(l%x>r%x){
pre.pb({0,1});
pre.pb({r%x+1,-1});
pre.pb({l%x,1});
pre.pb({x,-1});
}
else{
pre.pb({l%x,1});
pre.pb({r%x+1,-1});
}
}
sort(all(pre));
int sum=0,ans=0,last=pre[0].ff;
for(auto i:pre){
if(sum>0){
ans+=i.ff-last;
}
sum+=i.ss;
last=i.ff;
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1240 KB |
Output is correct |
3 |
Correct |
8 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
8 ms |
1240 KB |
Output is correct |
17 |
Correct |
115 ms |
7580 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
555 ms |
57028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
432 KB |
Output is correct |
2 |
Correct |
823 ms |
69108 KB |
Output is correct |
3 |
Correct |
782 ms |
68860 KB |
Output is correct |
4 |
Correct |
740 ms |
70112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
432 KB |
Output is correct |
2 |
Correct |
823 ms |
69108 KB |
Output is correct |
3 |
Correct |
782 ms |
68860 KB |
Output is correct |
4 |
Correct |
740 ms |
70112 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
763 ms |
69028 KB |
Output is correct |
7 |
Correct |
781 ms |
70300 KB |
Output is correct |
8 |
Correct |
767 ms |
69024 KB |
Output is correct |
9 |
Correct |
791 ms |
69020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
432 KB |
Output is correct |
2 |
Correct |
823 ms |
69108 KB |
Output is correct |
3 |
Correct |
782 ms |
68860 KB |
Output is correct |
4 |
Correct |
740 ms |
70112 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
74 ms |
7560 KB |
Output is correct |
7 |
Correct |
75 ms |
7668 KB |
Output is correct |
8 |
Correct |
85 ms |
7708 KB |
Output is correct |
9 |
Correct |
76 ms |
7540 KB |
Output is correct |
10 |
Correct |
72 ms |
8384 KB |
Output is correct |
11 |
Correct |
75 ms |
8376 KB |
Output is correct |
12 |
Correct |
74 ms |
8204 KB |
Output is correct |
13 |
Correct |
82 ms |
9152 KB |
Output is correct |
14 |
Correct |
78 ms |
7260 KB |
Output is correct |
15 |
Correct |
80 ms |
7620 KB |
Output is correct |
16 |
Correct |
79 ms |
8396 KB |
Output is correct |
17 |
Correct |
74 ms |
8464 KB |
Output is correct |
18 |
Correct |
786 ms |
69404 KB |
Output is correct |
19 |
Correct |
753 ms |
69356 KB |
Output is correct |
20 |
Correct |
797 ms |
70336 KB |
Output is correct |
21 |
Correct |
79 ms |
7624 KB |
Output is correct |
22 |
Correct |
74 ms |
8396 KB |
Output is correct |
23 |
Correct |
233 ms |
27520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
78 ms |
8964 KB |
Output is correct |
3 |
Correct |
84 ms |
8384 KB |
Output is correct |
4 |
Correct |
836 ms |
69788 KB |
Output is correct |
5 |
Correct |
79 ms |
7876 KB |
Output is correct |
6 |
Correct |
91 ms |
8384 KB |
Output is correct |
7 |
Correct |
77 ms |
7620 KB |
Output is correct |
8 |
Correct |
100 ms |
8128 KB |
Output is correct |
9 |
Correct |
76 ms |
8124 KB |
Output is correct |
10 |
Correct |
79 ms |
8152 KB |
Output is correct |
11 |
Correct |
77 ms |
8160 KB |
Output is correct |
12 |
Correct |
74 ms |
7620 KB |
Output is correct |
13 |
Correct |
81 ms |
9152 KB |
Output is correct |
14 |
Correct |
967 ms |
69024 KB |
Output is correct |
15 |
Correct |
83 ms |
7876 KB |
Output is correct |
16 |
Correct |
753 ms |
69076 KB |
Output is correct |
17 |
Correct |
790 ms |
69428 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1240 KB |
Output is correct |
3 |
Correct |
8 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
432 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
8 ms |
1240 KB |
Output is correct |
17 |
Correct |
115 ms |
7580 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
555 ms |
57028 KB |
Output is correct |
29 |
Correct |
0 ms |
432 KB |
Output is correct |
30 |
Correct |
823 ms |
69108 KB |
Output is correct |
31 |
Correct |
782 ms |
68860 KB |
Output is correct |
32 |
Correct |
740 ms |
70112 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
763 ms |
69028 KB |
Output is correct |
35 |
Correct |
781 ms |
70300 KB |
Output is correct |
36 |
Correct |
767 ms |
69024 KB |
Output is correct |
37 |
Correct |
791 ms |
69020 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
74 ms |
7560 KB |
Output is correct |
40 |
Correct |
75 ms |
7668 KB |
Output is correct |
41 |
Correct |
85 ms |
7708 KB |
Output is correct |
42 |
Correct |
76 ms |
7540 KB |
Output is correct |
43 |
Correct |
72 ms |
8384 KB |
Output is correct |
44 |
Correct |
75 ms |
8376 KB |
Output is correct |
45 |
Correct |
74 ms |
8204 KB |
Output is correct |
46 |
Correct |
82 ms |
9152 KB |
Output is correct |
47 |
Correct |
78 ms |
7260 KB |
Output is correct |
48 |
Correct |
80 ms |
7620 KB |
Output is correct |
49 |
Correct |
79 ms |
8396 KB |
Output is correct |
50 |
Correct |
74 ms |
8464 KB |
Output is correct |
51 |
Correct |
786 ms |
69404 KB |
Output is correct |
52 |
Correct |
753 ms |
69356 KB |
Output is correct |
53 |
Correct |
797 ms |
70336 KB |
Output is correct |
54 |
Correct |
79 ms |
7624 KB |
Output is correct |
55 |
Correct |
74 ms |
8396 KB |
Output is correct |
56 |
Correct |
233 ms |
27520 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
78 ms |
8964 KB |
Output is correct |
59 |
Correct |
84 ms |
8384 KB |
Output is correct |
60 |
Correct |
836 ms |
69788 KB |
Output is correct |
61 |
Correct |
79 ms |
7876 KB |
Output is correct |
62 |
Correct |
91 ms |
8384 KB |
Output is correct |
63 |
Correct |
77 ms |
7620 KB |
Output is correct |
64 |
Correct |
100 ms |
8128 KB |
Output is correct |
65 |
Correct |
76 ms |
8124 KB |
Output is correct |
66 |
Correct |
79 ms |
8152 KB |
Output is correct |
67 |
Correct |
77 ms |
8160 KB |
Output is correct |
68 |
Correct |
74 ms |
7620 KB |
Output is correct |
69 |
Correct |
81 ms |
9152 KB |
Output is correct |
70 |
Correct |
967 ms |
69024 KB |
Output is correct |
71 |
Correct |
83 ms |
7876 KB |
Output is correct |
72 |
Correct |
753 ms |
69076 KB |
Output is correct |
73 |
Correct |
790 ms |
69428 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
8 ms |
1240 KB |
Output is correct |
80 |
Correct |
795 ms |
68980 KB |
Output is correct |
81 |
Correct |
796 ms |
69796 KB |
Output is correct |
82 |
Correct |
787 ms |
69272 KB |
Output is correct |
83 |
Correct |
787 ms |
70300 KB |
Output is correct |
84 |
Correct |
826 ms |
69016 KB |
Output is correct |
85 |
Correct |
863 ms |
70044 KB |
Output is correct |
86 |
Correct |
244 ms |
28296 KB |
Output is correct |
87 |
Correct |
0 ms |
344 KB |
Output is correct |