#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
ll A,B;
cin >> n >> A >> B;
__int128_t LC = (__int128_t)1*A/__gcd(A,B+1)*B;
ll sum = 0;
vector<pair<ll,ll> > range;
for(int i=0;i<n;i++){
ll li,ri;
cin >> li >> ri;
sum += ri-li+1;
range.emplace_back(li,ri);
}
if(LC > (__int128_t)inf){
cout << sum << '\n';
return 0;
}
ll LCM = A/__gcd(A,B+1)*B;
vector<pair<ll,ll> > addi;
for(auto [li,ri] : range){
if(ri/LCM-li/LCM > 1){
addi.emplace_back(0,LCM-1);
}else if(ri/LCM-li/LCM == 1){
addi.emplace_back(li%LCM,LCM-1);
addi.emplace_back(0,ri%LCM);
}else{
addi.emplace_back(li%LCM,ri%LCM);
}
}
ll last = -1, tot = 0;
sort(addi.begin(),addi.end());
for(auto [li,ri] : addi){
tot += max(0ll,ri-max(last+1,li)+1);
last = max(last,ri);
}
cout << tot << '\n';
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:28:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for(auto [li,ri] : range){
| ^
strange_device.cpp:40:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
40 | for(auto [li,ri] : addi){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
5 ms |
856 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
43 ms |
4868 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
310 ms |
40504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
404 ms |
40616 KB |
Output is correct |
3 |
Correct |
421 ms |
41688 KB |
Output is correct |
4 |
Correct |
399 ms |
41152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
404 ms |
40616 KB |
Output is correct |
3 |
Correct |
421 ms |
41688 KB |
Output is correct |
4 |
Correct |
399 ms |
41152 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
416 ms |
41248 KB |
Output is correct |
7 |
Correct |
401 ms |
41144 KB |
Output is correct |
8 |
Correct |
408 ms |
41140 KB |
Output is correct |
9 |
Correct |
429 ms |
41112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
404 ms |
40616 KB |
Output is correct |
3 |
Correct |
421 ms |
41688 KB |
Output is correct |
4 |
Correct |
399 ms |
41152 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
42 ms |
5424 KB |
Output is correct |
7 |
Correct |
47 ms |
5464 KB |
Output is correct |
8 |
Correct |
43 ms |
5432 KB |
Output is correct |
9 |
Correct |
43 ms |
5412 KB |
Output is correct |
10 |
Correct |
42 ms |
5384 KB |
Output is correct |
11 |
Correct |
43 ms |
5456 KB |
Output is correct |
12 |
Correct |
41 ms |
5396 KB |
Output is correct |
13 |
Correct |
41 ms |
5444 KB |
Output is correct |
14 |
Correct |
41 ms |
5448 KB |
Output is correct |
15 |
Correct |
44 ms |
5412 KB |
Output is correct |
16 |
Correct |
46 ms |
5456 KB |
Output is correct |
17 |
Correct |
42 ms |
5444 KB |
Output is correct |
18 |
Correct |
410 ms |
41080 KB |
Output is correct |
19 |
Correct |
405 ms |
41436 KB |
Output is correct |
20 |
Correct |
462 ms |
41104 KB |
Output is correct |
21 |
Correct |
45 ms |
5440 KB |
Output is correct |
22 |
Correct |
41 ms |
5508 KB |
Output is correct |
23 |
Correct |
125 ms |
18404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
46 ms |
4884 KB |
Output is correct |
3 |
Correct |
47 ms |
5660 KB |
Output is correct |
4 |
Correct |
485 ms |
41536 KB |
Output is correct |
5 |
Correct |
47 ms |
5696 KB |
Output is correct |
6 |
Correct |
46 ms |
5716 KB |
Output is correct |
7 |
Correct |
45 ms |
5676 KB |
Output is correct |
8 |
Correct |
49 ms |
5640 KB |
Output is correct |
9 |
Correct |
45 ms |
5640 KB |
Output is correct |
10 |
Correct |
47 ms |
5748 KB |
Output is correct |
11 |
Correct |
48 ms |
5716 KB |
Output is correct |
12 |
Correct |
50 ms |
5708 KB |
Output is correct |
13 |
Correct |
48 ms |
5672 KB |
Output is correct |
14 |
Correct |
485 ms |
41336 KB |
Output is correct |
15 |
Correct |
46 ms |
5652 KB |
Output is correct |
16 |
Correct |
423 ms |
41228 KB |
Output is correct |
17 |
Correct |
414 ms |
42076 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
5 ms |
856 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
43 ms |
4868 KB |
Output is correct |
18 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
310 ms |
40504 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
404 ms |
40616 KB |
Output is correct |
31 |
Correct |
421 ms |
41688 KB |
Output is correct |
32 |
Correct |
399 ms |
41152 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
416 ms |
41248 KB |
Output is correct |
35 |
Correct |
401 ms |
41144 KB |
Output is correct |
36 |
Correct |
408 ms |
41140 KB |
Output is correct |
37 |
Correct |
429 ms |
41112 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
42 ms |
5424 KB |
Output is correct |
40 |
Correct |
47 ms |
5464 KB |
Output is correct |
41 |
Correct |
43 ms |
5432 KB |
Output is correct |
42 |
Correct |
43 ms |
5412 KB |
Output is correct |
43 |
Correct |
42 ms |
5384 KB |
Output is correct |
44 |
Correct |
43 ms |
5456 KB |
Output is correct |
45 |
Correct |
41 ms |
5396 KB |
Output is correct |
46 |
Correct |
41 ms |
5444 KB |
Output is correct |
47 |
Correct |
41 ms |
5448 KB |
Output is correct |
48 |
Correct |
44 ms |
5412 KB |
Output is correct |
49 |
Correct |
46 ms |
5456 KB |
Output is correct |
50 |
Correct |
42 ms |
5444 KB |
Output is correct |
51 |
Correct |
410 ms |
41080 KB |
Output is correct |
52 |
Correct |
405 ms |
41436 KB |
Output is correct |
53 |
Correct |
462 ms |
41104 KB |
Output is correct |
54 |
Correct |
45 ms |
5440 KB |
Output is correct |
55 |
Correct |
41 ms |
5508 KB |
Output is correct |
56 |
Correct |
125 ms |
18404 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
46 ms |
4884 KB |
Output is correct |
59 |
Correct |
47 ms |
5660 KB |
Output is correct |
60 |
Correct |
485 ms |
41536 KB |
Output is correct |
61 |
Correct |
47 ms |
5696 KB |
Output is correct |
62 |
Correct |
46 ms |
5716 KB |
Output is correct |
63 |
Correct |
45 ms |
5676 KB |
Output is correct |
64 |
Correct |
49 ms |
5640 KB |
Output is correct |
65 |
Correct |
45 ms |
5640 KB |
Output is correct |
66 |
Correct |
47 ms |
5748 KB |
Output is correct |
67 |
Correct |
48 ms |
5716 KB |
Output is correct |
68 |
Correct |
50 ms |
5708 KB |
Output is correct |
69 |
Correct |
48 ms |
5672 KB |
Output is correct |
70 |
Correct |
485 ms |
41336 KB |
Output is correct |
71 |
Correct |
46 ms |
5652 KB |
Output is correct |
72 |
Correct |
423 ms |
41228 KB |
Output is correct |
73 |
Correct |
414 ms |
42076 KB |
Output is correct |
74 |
Correct |
1 ms |
316 KB |
Output is correct |
75 |
Correct |
0 ms |
316 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
5 ms |
1240 KB |
Output is correct |
80 |
Correct |
477 ms |
41292 KB |
Output is correct |
81 |
Correct |
463 ms |
41404 KB |
Output is correct |
82 |
Correct |
429 ms |
41336 KB |
Output is correct |
83 |
Correct |
437 ms |
41456 KB |
Output is correct |
84 |
Correct |
459 ms |
41544 KB |
Output is correct |
85 |
Correct |
425 ms |
41464 KB |
Output is correct |
86 |
Correct |
127 ms |
18712 KB |
Output is correct |
87 |
Correct |
0 ms |
320 KB |
Output is correct |