#include<bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define f first
#define s second
#define ll long long
int n;
ll A, B;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>A>>B;
ll g = __gcd(A, B+1);
A /= g;
vector<pii> v;
bool all = 0;
for(int i=0;i<n;i++) {
ll l, r;
cin>>l>>r;
if(all) continue;
ll x = l/A;
x /= B;
ll y = r/A;
y /= B;
if(x==0 && y==0) {
v.push_back({l, r});
} else if(x==y) {
v.push_back({l%(A*B), r%(A*B)});
} else if(x+1==y) {
v.push_back({l%(A*B), (A*B)-1});
v.push_back({0, r%(A*B)});
} else {
all = 1;
}
}
if(all) {
cout<<A*B;
return 0;
}
sort(v.begin(), v.end());
ll ct = 0, last = -1;
for(int i=0;i<v.size();i++) {
if(last>=v[i].s) continue;
if(last<v[i].f) last = v[i].f-1;
ct += v[i].s-last;
last = v[i].s;
}
cout<<ct;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0;i<v.size();i++) {
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
736 KB |
Output is correct |
3 |
Correct |
5 ms |
736 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 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 |
1 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 |
4 ms |
1116 KB |
Output is correct |
17 |
Correct |
37 ms |
5836 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
344 KB |
Output is correct |
5 |
Correct |
230 ms |
17536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
331 ms |
17404 KB |
Output is correct |
3 |
Correct |
322 ms |
17076 KB |
Output is correct |
4 |
Correct |
303 ms |
53424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
331 ms |
17404 KB |
Output is correct |
3 |
Correct |
322 ms |
17076 KB |
Output is correct |
4 |
Correct |
303 ms |
53424 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
325 ms |
53856 KB |
Output is correct |
7 |
Correct |
335 ms |
53344 KB |
Output is correct |
8 |
Correct |
319 ms |
53420 KB |
Output is correct |
9 |
Correct |
341 ms |
53784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
331 ms |
17404 KB |
Output is correct |
3 |
Correct |
322 ms |
17076 KB |
Output is correct |
4 |
Correct |
303 ms |
53424 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
33 ms |
5844 KB |
Output is correct |
7 |
Correct |
37 ms |
5836 KB |
Output is correct |
8 |
Correct |
31 ms |
5828 KB |
Output is correct |
9 |
Correct |
33 ms |
5836 KB |
Output is correct |
10 |
Correct |
34 ms |
5796 KB |
Output is correct |
11 |
Correct |
34 ms |
5632 KB |
Output is correct |
12 |
Correct |
31 ms |
5740 KB |
Output is correct |
13 |
Correct |
40 ms |
5832 KB |
Output is correct |
14 |
Correct |
40 ms |
5832 KB |
Output is correct |
15 |
Correct |
38 ms |
5640 KB |
Output is correct |
16 |
Correct |
36 ms |
5832 KB |
Output is correct |
17 |
Correct |
32 ms |
5832 KB |
Output is correct |
18 |
Correct |
343 ms |
53420 KB |
Output is correct |
19 |
Correct |
346 ms |
53332 KB |
Output is correct |
20 |
Correct |
345 ms |
53308 KB |
Output is correct |
21 |
Correct |
37 ms |
5808 KB |
Output is correct |
22 |
Correct |
30 ms |
5920 KB |
Output is correct |
23 |
Correct |
98 ms |
19472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
36 ms |
2536 KB |
Output is correct |
3 |
Correct |
34 ms |
2516 KB |
Output is correct |
4 |
Correct |
363 ms |
17712 KB |
Output is correct |
5 |
Correct |
33 ms |
2516 KB |
Output is correct |
6 |
Correct |
34 ms |
2520 KB |
Output is correct |
7 |
Correct |
34 ms |
2520 KB |
Output is correct |
8 |
Correct |
35 ms |
2628 KB |
Output is correct |
9 |
Correct |
34 ms |
2520 KB |
Output is correct |
10 |
Correct |
34 ms |
2520 KB |
Output is correct |
11 |
Correct |
35 ms |
2496 KB |
Output is correct |
12 |
Correct |
30 ms |
2520 KB |
Output is correct |
13 |
Correct |
41 ms |
2516 KB |
Output is correct |
14 |
Correct |
344 ms |
18680 KB |
Output is correct |
15 |
Correct |
35 ms |
2520 KB |
Output is correct |
16 |
Correct |
341 ms |
53420 KB |
Output is correct |
17 |
Correct |
333 ms |
53180 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
736 KB |
Output is correct |
3 |
Correct |
5 ms |
736 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 |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 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 |
1 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 |
4 ms |
1116 KB |
Output is correct |
17 |
Correct |
37 ms |
5836 KB |
Output is correct |
18 |
Correct |
0 ms |
344 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 |
344 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 |
344 KB |
Output is correct |
28 |
Correct |
230 ms |
17536 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
331 ms |
17404 KB |
Output is correct |
31 |
Correct |
322 ms |
17076 KB |
Output is correct |
32 |
Correct |
303 ms |
53424 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
325 ms |
53856 KB |
Output is correct |
35 |
Correct |
335 ms |
53344 KB |
Output is correct |
36 |
Correct |
319 ms |
53420 KB |
Output is correct |
37 |
Correct |
341 ms |
53784 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
33 ms |
5844 KB |
Output is correct |
40 |
Correct |
37 ms |
5836 KB |
Output is correct |
41 |
Correct |
31 ms |
5828 KB |
Output is correct |
42 |
Correct |
33 ms |
5836 KB |
Output is correct |
43 |
Correct |
34 ms |
5796 KB |
Output is correct |
44 |
Correct |
34 ms |
5632 KB |
Output is correct |
45 |
Correct |
31 ms |
5740 KB |
Output is correct |
46 |
Correct |
40 ms |
5832 KB |
Output is correct |
47 |
Correct |
40 ms |
5832 KB |
Output is correct |
48 |
Correct |
38 ms |
5640 KB |
Output is correct |
49 |
Correct |
36 ms |
5832 KB |
Output is correct |
50 |
Correct |
32 ms |
5832 KB |
Output is correct |
51 |
Correct |
343 ms |
53420 KB |
Output is correct |
52 |
Correct |
346 ms |
53332 KB |
Output is correct |
53 |
Correct |
345 ms |
53308 KB |
Output is correct |
54 |
Correct |
37 ms |
5808 KB |
Output is correct |
55 |
Correct |
30 ms |
5920 KB |
Output is correct |
56 |
Correct |
98 ms |
19472 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
36 ms |
2536 KB |
Output is correct |
59 |
Correct |
34 ms |
2516 KB |
Output is correct |
60 |
Correct |
363 ms |
17712 KB |
Output is correct |
61 |
Correct |
33 ms |
2516 KB |
Output is correct |
62 |
Correct |
34 ms |
2520 KB |
Output is correct |
63 |
Correct |
34 ms |
2520 KB |
Output is correct |
64 |
Correct |
35 ms |
2628 KB |
Output is correct |
65 |
Correct |
34 ms |
2520 KB |
Output is correct |
66 |
Correct |
34 ms |
2520 KB |
Output is correct |
67 |
Correct |
35 ms |
2496 KB |
Output is correct |
68 |
Correct |
30 ms |
2520 KB |
Output is correct |
69 |
Correct |
41 ms |
2516 KB |
Output is correct |
70 |
Correct |
344 ms |
18680 KB |
Output is correct |
71 |
Correct |
35 ms |
2520 KB |
Output is correct |
72 |
Correct |
341 ms |
53420 KB |
Output is correct |
73 |
Correct |
333 ms |
53180 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 |
5 ms |
1172 KB |
Output is correct |
80 |
Correct |
383 ms |
53384 KB |
Output is correct |
81 |
Correct |
386 ms |
54476 KB |
Output is correct |
82 |
Correct |
352 ms |
53180 KB |
Output is correct |
83 |
Correct |
363 ms |
53548 KB |
Output is correct |
84 |
Correct |
355 ms |
53416 KB |
Output is correct |
85 |
Correct |
367 ms |
53200 KB |
Output is correct |
86 |
Correct |
108 ms |
20488 KB |
Output is correct |
87 |
Correct |
0 ms |
348 KB |
Output is correct |