#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 7;
void solve(){
long long n, A, B; cin >> n >> A >> B;
A = A / gcd(A, B + 1);
long long MOD = A * B;
long long ans = 0;
vector<pair<long long, long long>> intervals;
for(int i = 0; i < n;i++){
long long L, R; cin >> L >> R;
if(L / MOD == R / MOD){
intervals.push_back({L % MOD, R % MOD});
}else if(L / MOD + 1 == R / MOD){
intervals.push_back({L % MOD, MOD - 1});
intervals.push_back({0, R % MOD});
}else if(R / MOD >= L / MOD + 2){
cout << MOD << '\n';
return;
}
}
sort(intervals.begin(), intervals.end());
long long last = intervals[0].second + 1;
ans = intervals[0].second - intervals[0].first + 1;
for(int i = 1; i < intervals.size();i++){
ans += max(0LL, intervals[i].second - max(intervals[i].first, last) + 1);
last = max(last, intervals[i].second + 1);
}
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1; //cin >> T;
while(T--){
solve();
}
}
/*
how many unique pairs (t + t / B % A, t % B)
*/
Compilation message
strange_device.cpp: In function 'void solve()':
strange_device.cpp:28:21: 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]
28 | for(int i = 1; i < intervals.size();i++){
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
4 ms |
844 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
516 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
34 ms |
3532 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
193 ms |
18864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
259 ms |
18864 KB |
Output is correct |
3 |
Correct |
264 ms |
18864 KB |
Output is correct |
4 |
Correct |
277 ms |
18864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
259 ms |
18864 KB |
Output is correct |
3 |
Correct |
264 ms |
18864 KB |
Output is correct |
4 |
Correct |
277 ms |
18864 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
270 ms |
19024 KB |
Output is correct |
7 |
Correct |
272 ms |
19004 KB |
Output is correct |
8 |
Correct |
264 ms |
18864 KB |
Output is correct |
9 |
Correct |
285 ms |
18864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
259 ms |
18864 KB |
Output is correct |
3 |
Correct |
264 ms |
18864 KB |
Output is correct |
4 |
Correct |
277 ms |
18864 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
27 ms |
3532 KB |
Output is correct |
7 |
Correct |
28 ms |
3468 KB |
Output is correct |
8 |
Correct |
35 ms |
3532 KB |
Output is correct |
9 |
Correct |
27 ms |
3532 KB |
Output is correct |
10 |
Correct |
28 ms |
3532 KB |
Output is correct |
11 |
Correct |
27 ms |
3532 KB |
Output is correct |
12 |
Correct |
25 ms |
3532 KB |
Output is correct |
13 |
Correct |
28 ms |
3544 KB |
Output is correct |
14 |
Correct |
25 ms |
3532 KB |
Output is correct |
15 |
Correct |
30 ms |
3532 KB |
Output is correct |
16 |
Correct |
28 ms |
3532 KB |
Output is correct |
17 |
Correct |
27 ms |
3532 KB |
Output is correct |
18 |
Correct |
251 ms |
18832 KB |
Output is correct |
19 |
Correct |
244 ms |
18852 KB |
Output is correct |
20 |
Correct |
269 ms |
18868 KB |
Output is correct |
21 |
Correct |
28 ms |
3532 KB |
Output is correct |
22 |
Correct |
25 ms |
3536 KB |
Output is correct |
23 |
Correct |
75 ms |
10824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
28 ms |
3532 KB |
Output is correct |
3 |
Correct |
28 ms |
3532 KB |
Output is correct |
4 |
Correct |
278 ms |
18864 KB |
Output is correct |
5 |
Correct |
29 ms |
3532 KB |
Output is correct |
6 |
Correct |
28 ms |
3548 KB |
Output is correct |
7 |
Correct |
37 ms |
3532 KB |
Output is correct |
8 |
Correct |
29 ms |
3520 KB |
Output is correct |
9 |
Correct |
30 ms |
3704 KB |
Output is correct |
10 |
Correct |
28 ms |
3532 KB |
Output is correct |
11 |
Correct |
28 ms |
3544 KB |
Output is correct |
12 |
Correct |
27 ms |
3616 KB |
Output is correct |
13 |
Correct |
28 ms |
3700 KB |
Output is correct |
14 |
Correct |
303 ms |
19008 KB |
Output is correct |
15 |
Correct |
30 ms |
3532 KB |
Output is correct |
16 |
Correct |
295 ms |
18872 KB |
Output is correct |
17 |
Correct |
268 ms |
19044 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
4 ms |
724 KB |
Output is correct |
3 |
Correct |
4 ms |
844 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
516 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
34 ms |
3532 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
193 ms |
18864 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
259 ms |
18864 KB |
Output is correct |
31 |
Correct |
264 ms |
18864 KB |
Output is correct |
32 |
Correct |
277 ms |
18864 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
270 ms |
19024 KB |
Output is correct |
35 |
Correct |
272 ms |
19004 KB |
Output is correct |
36 |
Correct |
264 ms |
18864 KB |
Output is correct |
37 |
Correct |
285 ms |
18864 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
27 ms |
3532 KB |
Output is correct |
40 |
Correct |
28 ms |
3468 KB |
Output is correct |
41 |
Correct |
35 ms |
3532 KB |
Output is correct |
42 |
Correct |
27 ms |
3532 KB |
Output is correct |
43 |
Correct |
28 ms |
3532 KB |
Output is correct |
44 |
Correct |
27 ms |
3532 KB |
Output is correct |
45 |
Correct |
25 ms |
3532 KB |
Output is correct |
46 |
Correct |
28 ms |
3544 KB |
Output is correct |
47 |
Correct |
25 ms |
3532 KB |
Output is correct |
48 |
Correct |
30 ms |
3532 KB |
Output is correct |
49 |
Correct |
28 ms |
3532 KB |
Output is correct |
50 |
Correct |
27 ms |
3532 KB |
Output is correct |
51 |
Correct |
251 ms |
18832 KB |
Output is correct |
52 |
Correct |
244 ms |
18852 KB |
Output is correct |
53 |
Correct |
269 ms |
18868 KB |
Output is correct |
54 |
Correct |
28 ms |
3532 KB |
Output is correct |
55 |
Correct |
25 ms |
3536 KB |
Output is correct |
56 |
Correct |
75 ms |
10824 KB |
Output is correct |
57 |
Correct |
1 ms |
504 KB |
Output is correct |
58 |
Correct |
28 ms |
3532 KB |
Output is correct |
59 |
Correct |
28 ms |
3532 KB |
Output is correct |
60 |
Correct |
278 ms |
18864 KB |
Output is correct |
61 |
Correct |
29 ms |
3532 KB |
Output is correct |
62 |
Correct |
28 ms |
3548 KB |
Output is correct |
63 |
Correct |
37 ms |
3532 KB |
Output is correct |
64 |
Correct |
29 ms |
3520 KB |
Output is correct |
65 |
Correct |
30 ms |
3704 KB |
Output is correct |
66 |
Correct |
28 ms |
3532 KB |
Output is correct |
67 |
Correct |
28 ms |
3544 KB |
Output is correct |
68 |
Correct |
27 ms |
3616 KB |
Output is correct |
69 |
Correct |
28 ms |
3700 KB |
Output is correct |
70 |
Correct |
303 ms |
19008 KB |
Output is correct |
71 |
Correct |
30 ms |
3532 KB |
Output is correct |
72 |
Correct |
295 ms |
18872 KB |
Output is correct |
73 |
Correct |
268 ms |
19044 KB |
Output is correct |
74 |
Correct |
1 ms |
336 KB |
Output is correct |
75 |
Correct |
1 ms |
336 KB |
Output is correct |
76 |
Correct |
1 ms |
336 KB |
Output is correct |
77 |
Correct |
1 ms |
336 KB |
Output is correct |
78 |
Correct |
1 ms |
336 KB |
Output is correct |
79 |
Correct |
4 ms |
1104 KB |
Output is correct |
80 |
Correct |
317 ms |
53944 KB |
Output is correct |
81 |
Correct |
331 ms |
54184 KB |
Output is correct |
82 |
Correct |
309 ms |
54188 KB |
Output is correct |
83 |
Correct |
310 ms |
54076 KB |
Output is correct |
84 |
Correct |
325 ms |
54056 KB |
Output is correct |
85 |
Correct |
350 ms |
53928 KB |
Output is correct |
86 |
Correct |
82 ms |
20532 KB |
Output is correct |
87 |
Correct |
1 ms |
336 KB |
Output is correct |