#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,A,B;
cin >> n >> A >> B;
__int128 modulus = __int128(A/gcd(A,B+1))*__int128(B);
set<__int128> answers;
vector<pair<__int128,bool>> events;
for(int i=1;i<=n;i++){
int tl,tr;cin>>tl>>tr;__int128 l = tl,r=tr;
__int128 block_l = l/modulus;
__int128 block_r = r/modulus;
l%=modulus;
r%=modulus;
if(block_l == block_r){
events.emplace_back(l,false);
events.emplace_back(r+1,true);
} else if(block_l+1 == block_r){
events.emplace_back(l,false);
events.emplace_back(r+1,true);
events.emplace_back(0,false);
events.emplace_back(modulus,true);
} else {
cout << (int)modulus << '\n';
return 0;
}
}
sort(events.begin(), events.end());
__int128 last = -1;
int curractive = 0;
__int128 currans = 0;
for(auto[idx,type]:events){
if(type){
if(--curractive==0){
currans+=idx-last;
}
} else{
if(curractive++==0){
last = idx;
}
}
}
cout << (int)currans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
1500 KB |
Output is correct |
3 |
Correct |
4 ms |
1500 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 |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
5 ms |
1496 KB |
Output is correct |
17 |
Correct |
53 ms |
9420 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
348 KB |
Output is correct |
5 |
Correct |
310 ms |
89112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
428 ms |
66984 KB |
Output is correct |
3 |
Correct |
463 ms |
100840 KB |
Output is correct |
4 |
Correct |
448 ms |
101272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
428 ms |
66984 KB |
Output is correct |
3 |
Correct |
463 ms |
100840 KB |
Output is correct |
4 |
Correct |
448 ms |
101272 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
438 ms |
100592 KB |
Output is correct |
7 |
Correct |
423 ms |
100128 KB |
Output is correct |
8 |
Correct |
451 ms |
102028 KB |
Output is correct |
9 |
Correct |
591 ms |
101100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
428 ms |
66984 KB |
Output is correct |
3 |
Correct |
463 ms |
100840 KB |
Output is correct |
4 |
Correct |
448 ms |
101272 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
41 ms |
12240 KB |
Output is correct |
7 |
Correct |
44 ms |
12496 KB |
Output is correct |
8 |
Correct |
38 ms |
12488 KB |
Output is correct |
9 |
Correct |
46 ms |
13256 KB |
Output is correct |
10 |
Correct |
39 ms |
13256 KB |
Output is correct |
11 |
Correct |
42 ms |
12996 KB |
Output is correct |
12 |
Correct |
42 ms |
11460 KB |
Output is correct |
13 |
Correct |
50 ms |
13008 KB |
Output is correct |
14 |
Correct |
38 ms |
13252 KB |
Output is correct |
15 |
Correct |
52 ms |
12040 KB |
Output is correct |
16 |
Correct |
52 ms |
12236 KB |
Output is correct |
17 |
Correct |
38 ms |
11720 KB |
Output is correct |
18 |
Correct |
445 ms |
102040 KB |
Output is correct |
19 |
Correct |
435 ms |
102192 KB |
Output is correct |
20 |
Correct |
661 ms |
100388 KB |
Output is correct |
21 |
Correct |
52 ms |
11980 KB |
Output is correct |
22 |
Correct |
39 ms |
11468 KB |
Output is correct |
23 |
Correct |
120 ms |
43480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
52 ms |
12996 KB |
Output is correct |
3 |
Correct |
49 ms |
13456 KB |
Output is correct |
4 |
Correct |
668 ms |
101112 KB |
Output is correct |
5 |
Correct |
53 ms |
13000 KB |
Output is correct |
6 |
Correct |
49 ms |
12736 KB |
Output is correct |
7 |
Correct |
50 ms |
13028 KB |
Output is correct |
8 |
Correct |
55 ms |
12228 KB |
Output is correct |
9 |
Correct |
47 ms |
12992 KB |
Output is correct |
10 |
Correct |
55 ms |
13256 KB |
Output is correct |
11 |
Correct |
51 ms |
11976 KB |
Output is correct |
12 |
Correct |
46 ms |
13008 KB |
Output is correct |
13 |
Correct |
51 ms |
13256 KB |
Output is correct |
14 |
Correct |
603 ms |
101284 KB |
Output is correct |
15 |
Correct |
53 ms |
11728 KB |
Output is correct |
16 |
Correct |
417 ms |
101016 KB |
Output is correct |
17 |
Correct |
439 ms |
100764 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
1500 KB |
Output is correct |
3 |
Correct |
4 ms |
1500 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 |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
5 ms |
1496 KB |
Output is correct |
17 |
Correct |
53 ms |
9420 KB |
Output is correct |
18 |
Correct |
0 ms |
348 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 |
348 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 |
348 KB |
Output is correct |
28 |
Correct |
310 ms |
89112 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
428 ms |
66984 KB |
Output is correct |
31 |
Correct |
463 ms |
100840 KB |
Output is correct |
32 |
Correct |
448 ms |
101272 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
438 ms |
100592 KB |
Output is correct |
35 |
Correct |
423 ms |
100128 KB |
Output is correct |
36 |
Correct |
451 ms |
102028 KB |
Output is correct |
37 |
Correct |
591 ms |
101100 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
41 ms |
12240 KB |
Output is correct |
40 |
Correct |
44 ms |
12496 KB |
Output is correct |
41 |
Correct |
38 ms |
12488 KB |
Output is correct |
42 |
Correct |
46 ms |
13256 KB |
Output is correct |
43 |
Correct |
39 ms |
13256 KB |
Output is correct |
44 |
Correct |
42 ms |
12996 KB |
Output is correct |
45 |
Correct |
42 ms |
11460 KB |
Output is correct |
46 |
Correct |
50 ms |
13008 KB |
Output is correct |
47 |
Correct |
38 ms |
13252 KB |
Output is correct |
48 |
Correct |
52 ms |
12040 KB |
Output is correct |
49 |
Correct |
52 ms |
12236 KB |
Output is correct |
50 |
Correct |
38 ms |
11720 KB |
Output is correct |
51 |
Correct |
445 ms |
102040 KB |
Output is correct |
52 |
Correct |
435 ms |
102192 KB |
Output is correct |
53 |
Correct |
661 ms |
100388 KB |
Output is correct |
54 |
Correct |
52 ms |
11980 KB |
Output is correct |
55 |
Correct |
39 ms |
11468 KB |
Output is correct |
56 |
Correct |
120 ms |
43480 KB |
Output is correct |
57 |
Correct |
0 ms |
344 KB |
Output is correct |
58 |
Correct |
52 ms |
12996 KB |
Output is correct |
59 |
Correct |
49 ms |
13456 KB |
Output is correct |
60 |
Correct |
668 ms |
101112 KB |
Output is correct |
61 |
Correct |
53 ms |
13000 KB |
Output is correct |
62 |
Correct |
49 ms |
12736 KB |
Output is correct |
63 |
Correct |
50 ms |
13028 KB |
Output is correct |
64 |
Correct |
55 ms |
12228 KB |
Output is correct |
65 |
Correct |
47 ms |
12992 KB |
Output is correct |
66 |
Correct |
55 ms |
13256 KB |
Output is correct |
67 |
Correct |
51 ms |
11976 KB |
Output is correct |
68 |
Correct |
46 ms |
13008 KB |
Output is correct |
69 |
Correct |
51 ms |
13256 KB |
Output is correct |
70 |
Correct |
603 ms |
101284 KB |
Output is correct |
71 |
Correct |
53 ms |
11728 KB |
Output is correct |
72 |
Correct |
417 ms |
101016 KB |
Output is correct |
73 |
Correct |
439 ms |
100764 KB |
Output is correct |
74 |
Correct |
0 ms |
344 KB |
Output is correct |
75 |
Correct |
0 ms |
556 KB |
Output is correct |
76 |
Correct |
1 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 |
4 ms |
1820 KB |
Output is correct |
80 |
Correct |
662 ms |
100764 KB |
Output is correct |
81 |
Correct |
665 ms |
100648 KB |
Output is correct |
82 |
Correct |
587 ms |
100652 KB |
Output is correct |
83 |
Correct |
591 ms |
100876 KB |
Output is correct |
84 |
Correct |
590 ms |
101576 KB |
Output is correct |
85 |
Correct |
586 ms |
102300 KB |
Output is correct |
86 |
Correct |
120 ms |
43184 KB |
Output is correct |
87 |
Correct |
0 ms |
348 KB |
Output is correct |