#include <bits/stdc++.h>
#define int long long
using namespace std;
int gcd(int a,int b){
while (b) b^=a^=b^=a%=b;
return a;
}
signed main(){
int n,a,b;
cin>>n>>a>>b;
a/=gcd(a,b+1);
pair <int,int> p[n];
for (int i=0; i<n; i++) cin>>p[i].first>>p[i].second;
int lim=(a<=(1e18+5)/b?a*b:1e18+5);
vector <pair <int,int> > v;
for (int i=0; i<n; i++){
if (p[i].second-p[i].first+1>=lim){
cout<<lim;
return 0;
}
p[i].first%=lim;
p[i].second%=lim;
if (p[i].first<=p[i].second) v.push_back({p[i].first,p[i].second});
else {
v.push_back({p[i].first,lim-1});
v.push_back({0,p[i].second});
}
}
sort(v.begin(),v.end());
int ans=0,lb=v[0].first,rb=v[0].second;
for (int i=1; i<v.size(); i++){
if (v[i].first>rb){
ans+=rb-lb+1;
rb=v[i].second;
lb=v[i].first;
} else rb=max(rb,v[i].second);
}
cout<<ans+rb-lb+1;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:31:17: 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]
31 | for (int i=1; i<v.size(); i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
16 ms |
1260 KB |
Output is correct |
3 |
Correct |
16 ms |
1280 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
15 ms |
1260 KB |
Output is correct |
17 |
Correct |
160 ms |
6808 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1066 ms |
32724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1499 ms |
32748 KB |
Output is correct |
3 |
Correct |
1461 ms |
32848 KB |
Output is correct |
4 |
Correct |
1468 ms |
32852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1499 ms |
32748 KB |
Output is correct |
3 |
Correct |
1461 ms |
32848 KB |
Output is correct |
4 |
Correct |
1468 ms |
32852 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1467 ms |
32800 KB |
Output is correct |
7 |
Correct |
1495 ms |
32848 KB |
Output is correct |
8 |
Correct |
1481 ms |
32836 KB |
Output is correct |
9 |
Correct |
1529 ms |
32852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1499 ms |
32748 KB |
Output is correct |
3 |
Correct |
1461 ms |
32848 KB |
Output is correct |
4 |
Correct |
1468 ms |
32852 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
151 ms |
5856 KB |
Output is correct |
7 |
Correct |
151 ms |
5868 KB |
Output is correct |
8 |
Correct |
146 ms |
5856 KB |
Output is correct |
9 |
Correct |
149 ms |
5864 KB |
Output is correct |
10 |
Correct |
149 ms |
5984 KB |
Output is correct |
11 |
Correct |
149 ms |
5856 KB |
Output is correct |
12 |
Correct |
155 ms |
5856 KB |
Output is correct |
13 |
Correct |
150 ms |
5884 KB |
Output is correct |
14 |
Correct |
146 ms |
5984 KB |
Output is correct |
15 |
Correct |
150 ms |
5856 KB |
Output is correct |
16 |
Correct |
150 ms |
5856 KB |
Output is correct |
17 |
Correct |
148 ms |
5984 KB |
Output is correct |
18 |
Correct |
1475 ms |
34704 KB |
Output is correct |
19 |
Correct |
1474 ms |
32848 KB |
Output is correct |
20 |
Correct |
1529 ms |
32808 KB |
Output is correct |
21 |
Correct |
152 ms |
6240 KB |
Output is correct |
22 |
Correct |
144 ms |
6112 KB |
Output is correct |
23 |
Correct |
498 ms |
15856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
153 ms |
6112 KB |
Output is correct |
3 |
Correct |
156 ms |
6112 KB |
Output is correct |
4 |
Correct |
1549 ms |
32848 KB |
Output is correct |
5 |
Correct |
149 ms |
6112 KB |
Output is correct |
6 |
Correct |
153 ms |
6264 KB |
Output is correct |
7 |
Correct |
150 ms |
6240 KB |
Output is correct |
8 |
Correct |
153 ms |
6240 KB |
Output is correct |
9 |
Correct |
163 ms |
6240 KB |
Output is correct |
10 |
Correct |
151 ms |
6240 KB |
Output is correct |
11 |
Correct |
152 ms |
6112 KB |
Output is correct |
12 |
Correct |
143 ms |
6112 KB |
Output is correct |
13 |
Correct |
154 ms |
6112 KB |
Output is correct |
14 |
Correct |
1520 ms |
32780 KB |
Output is correct |
15 |
Correct |
154 ms |
6240 KB |
Output is correct |
16 |
Correct |
1469 ms |
33044 KB |
Output is correct |
17 |
Correct |
1468 ms |
33144 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
16 ms |
1260 KB |
Output is correct |
3 |
Correct |
16 ms |
1280 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
15 ms |
1260 KB |
Output is correct |
17 |
Correct |
160 ms |
6808 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
1066 ms |
32724 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1499 ms |
32748 KB |
Output is correct |
31 |
Correct |
1461 ms |
32848 KB |
Output is correct |
32 |
Correct |
1468 ms |
32852 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1467 ms |
32800 KB |
Output is correct |
35 |
Correct |
1495 ms |
32848 KB |
Output is correct |
36 |
Correct |
1481 ms |
32836 KB |
Output is correct |
37 |
Correct |
1529 ms |
32852 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
151 ms |
5856 KB |
Output is correct |
40 |
Correct |
151 ms |
5868 KB |
Output is correct |
41 |
Correct |
146 ms |
5856 KB |
Output is correct |
42 |
Correct |
149 ms |
5864 KB |
Output is correct |
43 |
Correct |
149 ms |
5984 KB |
Output is correct |
44 |
Correct |
149 ms |
5856 KB |
Output is correct |
45 |
Correct |
155 ms |
5856 KB |
Output is correct |
46 |
Correct |
150 ms |
5884 KB |
Output is correct |
47 |
Correct |
146 ms |
5984 KB |
Output is correct |
48 |
Correct |
150 ms |
5856 KB |
Output is correct |
49 |
Correct |
150 ms |
5856 KB |
Output is correct |
50 |
Correct |
148 ms |
5984 KB |
Output is correct |
51 |
Correct |
1475 ms |
34704 KB |
Output is correct |
52 |
Correct |
1474 ms |
32848 KB |
Output is correct |
53 |
Correct |
1529 ms |
32808 KB |
Output is correct |
54 |
Correct |
152 ms |
6240 KB |
Output is correct |
55 |
Correct |
144 ms |
6112 KB |
Output is correct |
56 |
Correct |
498 ms |
15856 KB |
Output is correct |
57 |
Correct |
1 ms |
364 KB |
Output is correct |
58 |
Correct |
153 ms |
6112 KB |
Output is correct |
59 |
Correct |
156 ms |
6112 KB |
Output is correct |
60 |
Correct |
1549 ms |
32848 KB |
Output is correct |
61 |
Correct |
149 ms |
6112 KB |
Output is correct |
62 |
Correct |
153 ms |
6264 KB |
Output is correct |
63 |
Correct |
150 ms |
6240 KB |
Output is correct |
64 |
Correct |
153 ms |
6240 KB |
Output is correct |
65 |
Correct |
163 ms |
6240 KB |
Output is correct |
66 |
Correct |
151 ms |
6240 KB |
Output is correct |
67 |
Correct |
152 ms |
6112 KB |
Output is correct |
68 |
Correct |
143 ms |
6112 KB |
Output is correct |
69 |
Correct |
154 ms |
6112 KB |
Output is correct |
70 |
Correct |
1520 ms |
32780 KB |
Output is correct |
71 |
Correct |
154 ms |
6240 KB |
Output is correct |
72 |
Correct |
1469 ms |
33044 KB |
Output is correct |
73 |
Correct |
1468 ms |
33144 KB |
Output is correct |
74 |
Correct |
1 ms |
384 KB |
Output is correct |
75 |
Correct |
1 ms |
364 KB |
Output is correct |
76 |
Correct |
1 ms |
364 KB |
Output is correct |
77 |
Correct |
1 ms |
364 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
15 ms |
1260 KB |
Output is correct |
80 |
Correct |
1549 ms |
32724 KB |
Output is correct |
81 |
Correct |
1574 ms |
32596 KB |
Output is correct |
82 |
Correct |
1534 ms |
32636 KB |
Output is correct |
83 |
Correct |
1509 ms |
32764 KB |
Output is correct |
84 |
Correct |
1503 ms |
32720 KB |
Output is correct |
85 |
Correct |
1526 ms |
32724 KB |
Output is correct |
86 |
Correct |
491 ms |
15576 KB |
Output is correct |
87 |
Correct |
1 ms |
364 KB |
Output is correct |