#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a,b;
const int inf = 2e18+5;
#define gcd(a,b) __gcd(a,b)
signed main() {
cin >> n >> a >> b;
int p;
if(a/gcd(a,b+1) > inf/b) {
p = inf;
} else {
p = a / gcd(a,b+1) * b;
}
vector<pair<int,int>> range;
for(int i = 0; i < n; i++) {
int l,r; cin >> l >> r;
if(r-l >= p) {
range.push_back({0,p-1});
} else {
l = l % p, r = r % p;
if(l > r) {
range.push_back({l, p-1});
range.push_back({0, r});
} else {
range.push_back({l,r});
}
}
}
sort(begin(range), end(range));
vector<pair<int,int>> jake;
for(auto it : range) {
if(jake.empty() or jake.back().second < it.first) {
jake.push_back(it);
} else {
jake.back().second = max(jake.back().second, it.second);
}
}
int res = 0;
for(auto it : jake) res += it.second - it.first + 1;
cout << res <<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
14 ms |
1152 KB |
Output is correct |
3 |
Correct |
14 ms |
1232 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
13 ms |
1140 KB |
Output is correct |
17 |
Correct |
139 ms |
8664 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
912 ms |
41212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1338 ms |
57180 KB |
Output is correct |
3 |
Correct |
1349 ms |
77708 KB |
Output is correct |
4 |
Correct |
1276 ms |
77772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1338 ms |
57180 KB |
Output is correct |
3 |
Correct |
1349 ms |
77708 KB |
Output is correct |
4 |
Correct |
1276 ms |
77772 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1298 ms |
77636 KB |
Output is correct |
7 |
Correct |
1305 ms |
77648 KB |
Output is correct |
8 |
Correct |
1317 ms |
77780 KB |
Output is correct |
9 |
Correct |
1321 ms |
77648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1338 ms |
57180 KB |
Output is correct |
3 |
Correct |
1349 ms |
77708 KB |
Output is correct |
4 |
Correct |
1276 ms |
77772 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
136 ms |
8568 KB |
Output is correct |
7 |
Correct |
160 ms |
8640 KB |
Output is correct |
8 |
Correct |
140 ms |
8556 KB |
Output is correct |
9 |
Correct |
130 ms |
8532 KB |
Output is correct |
10 |
Correct |
126 ms |
8560 KB |
Output is correct |
11 |
Correct |
133 ms |
8716 KB |
Output is correct |
12 |
Correct |
146 ms |
8556 KB |
Output is correct |
13 |
Correct |
134 ms |
8568 KB |
Output is correct |
14 |
Correct |
132 ms |
8668 KB |
Output is correct |
15 |
Correct |
130 ms |
8524 KB |
Output is correct |
16 |
Correct |
141 ms |
8552 KB |
Output is correct |
17 |
Correct |
129 ms |
8620 KB |
Output is correct |
18 |
Correct |
1321 ms |
77744 KB |
Output is correct |
19 |
Correct |
1272 ms |
77600 KB |
Output is correct |
20 |
Correct |
1373 ms |
77648 KB |
Output is correct |
21 |
Correct |
129 ms |
8636 KB |
Output is correct |
22 |
Correct |
134 ms |
8632 KB |
Output is correct |
23 |
Correct |
426 ms |
18456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
141 ms |
8572 KB |
Output is correct |
3 |
Correct |
144 ms |
8608 KB |
Output is correct |
4 |
Correct |
1430 ms |
57088 KB |
Output is correct |
5 |
Correct |
137 ms |
8616 KB |
Output is correct |
6 |
Correct |
145 ms |
8632 KB |
Output is correct |
7 |
Correct |
128 ms |
8536 KB |
Output is correct |
8 |
Correct |
132 ms |
8608 KB |
Output is correct |
9 |
Correct |
129 ms |
8528 KB |
Output is correct |
10 |
Correct |
141 ms |
8644 KB |
Output is correct |
11 |
Correct |
140 ms |
8552 KB |
Output is correct |
12 |
Correct |
129 ms |
8604 KB |
Output is correct |
13 |
Correct |
128 ms |
8564 KB |
Output is correct |
14 |
Correct |
1347 ms |
77716 KB |
Output is correct |
15 |
Correct |
129 ms |
8548 KB |
Output is correct |
16 |
Correct |
1279 ms |
77664 KB |
Output is correct |
17 |
Correct |
1290 ms |
77628 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
14 ms |
1152 KB |
Output is correct |
3 |
Correct |
14 ms |
1232 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
13 ms |
1140 KB |
Output is correct |
17 |
Correct |
139 ms |
8664 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
912 ms |
41212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1338 ms |
57180 KB |
Output is correct |
31 |
Correct |
1349 ms |
77708 KB |
Output is correct |
32 |
Correct |
1276 ms |
77772 KB |
Output is correct |
33 |
Correct |
1 ms |
296 KB |
Output is correct |
34 |
Correct |
1298 ms |
77636 KB |
Output is correct |
35 |
Correct |
1305 ms |
77648 KB |
Output is correct |
36 |
Correct |
1317 ms |
77780 KB |
Output is correct |
37 |
Correct |
1321 ms |
77648 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
136 ms |
8568 KB |
Output is correct |
40 |
Correct |
160 ms |
8640 KB |
Output is correct |
41 |
Correct |
140 ms |
8556 KB |
Output is correct |
42 |
Correct |
130 ms |
8532 KB |
Output is correct |
43 |
Correct |
126 ms |
8560 KB |
Output is correct |
44 |
Correct |
133 ms |
8716 KB |
Output is correct |
45 |
Correct |
146 ms |
8556 KB |
Output is correct |
46 |
Correct |
134 ms |
8568 KB |
Output is correct |
47 |
Correct |
132 ms |
8668 KB |
Output is correct |
48 |
Correct |
130 ms |
8524 KB |
Output is correct |
49 |
Correct |
141 ms |
8552 KB |
Output is correct |
50 |
Correct |
129 ms |
8620 KB |
Output is correct |
51 |
Correct |
1321 ms |
77744 KB |
Output is correct |
52 |
Correct |
1272 ms |
77600 KB |
Output is correct |
53 |
Correct |
1373 ms |
77648 KB |
Output is correct |
54 |
Correct |
129 ms |
8636 KB |
Output is correct |
55 |
Correct |
134 ms |
8632 KB |
Output is correct |
56 |
Correct |
426 ms |
18456 KB |
Output is correct |
57 |
Correct |
0 ms |
300 KB |
Output is correct |
58 |
Correct |
141 ms |
8572 KB |
Output is correct |
59 |
Correct |
144 ms |
8608 KB |
Output is correct |
60 |
Correct |
1430 ms |
57088 KB |
Output is correct |
61 |
Correct |
137 ms |
8616 KB |
Output is correct |
62 |
Correct |
145 ms |
8632 KB |
Output is correct |
63 |
Correct |
128 ms |
8536 KB |
Output is correct |
64 |
Correct |
132 ms |
8608 KB |
Output is correct |
65 |
Correct |
129 ms |
8528 KB |
Output is correct |
66 |
Correct |
141 ms |
8644 KB |
Output is correct |
67 |
Correct |
140 ms |
8552 KB |
Output is correct |
68 |
Correct |
129 ms |
8604 KB |
Output is correct |
69 |
Correct |
128 ms |
8564 KB |
Output is correct |
70 |
Correct |
1347 ms |
77716 KB |
Output is correct |
71 |
Correct |
129 ms |
8548 KB |
Output is correct |
72 |
Correct |
1279 ms |
77664 KB |
Output is correct |
73 |
Correct |
1290 ms |
77628 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
0 ms |
300 KB |
Output is correct |
77 |
Correct |
0 ms |
300 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
14 ms |
1148 KB |
Output is correct |
80 |
Correct |
1388 ms |
77588 KB |
Output is correct |
81 |
Correct |
1339 ms |
77760 KB |
Output is correct |
82 |
Correct |
1313 ms |
77632 KB |
Output is correct |
83 |
Correct |
1372 ms |
77560 KB |
Output is correct |
84 |
Correct |
1329 ms |
77080 KB |
Output is correct |
85 |
Correct |
1961 ms |
77040 KB |
Output is correct |
86 |
Correct |
430 ms |
18568 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |