// 34 days to apio!
#include <bits/stdc++.h>
using namespace std;
#define int long long
main() {
int n, a, b, p; cin >> n >> a >> b;
a /= __gcd(a,b+1);
if(a>1e18/b) p=1e18;
else p=a * b;
vector<pair<int,int>> v;
for(int i=0;i<n;i++) {
int l, r; cin >> l >> r;
if(r-l>p) {cout<<p; return 0;}
else if(l/p == r/p) v.push_back({l%p,r%p});
else {
v.push_back({l%p,p-1});
v.push_back({0,r%p});
}
}
sort(v.begin(),v.end(),greater<pair<int,int>>());
int ans = 0;
while(v.size()>=2) {
if(end(v)[-2].first<=end(v)[-1].second) end(v)[-2]={end(v)[-1].first,max(end(v)[-1].second,end(v)[-2].second)};
else ans += end(v)[-1].second-end(v)[-1].first+1;
v.pop_back();
}
cout << ans + v[0].second - v[0].first + 1;
}
Compilation message
strange_device.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
5 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
1368 KB |
Output is correct |
3 |
Correct |
10 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
10 ms |
1116 KB |
Output is correct |
17 |
Correct |
99 ms |
5804 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
528 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
717 ms |
41188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1078 ms |
53148 KB |
Output is correct |
3 |
Correct |
1006 ms |
53668 KB |
Output is correct |
4 |
Correct |
1004 ms |
53232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1078 ms |
53148 KB |
Output is correct |
3 |
Correct |
1006 ms |
53668 KB |
Output is correct |
4 |
Correct |
1004 ms |
53232 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1031 ms |
53460 KB |
Output is correct |
7 |
Correct |
1043 ms |
53484 KB |
Output is correct |
8 |
Correct |
1267 ms |
53548 KB |
Output is correct |
9 |
Correct |
1004 ms |
53356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1078 ms |
53148 KB |
Output is correct |
3 |
Correct |
1006 ms |
53668 KB |
Output is correct |
4 |
Correct |
1004 ms |
53232 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
99 ms |
5756 KB |
Output is correct |
7 |
Correct |
114 ms |
5936 KB |
Output is correct |
8 |
Correct |
105 ms |
5680 KB |
Output is correct |
9 |
Correct |
98 ms |
5820 KB |
Output is correct |
10 |
Correct |
100 ms |
5792 KB |
Output is correct |
11 |
Correct |
109 ms |
5620 KB |
Output is correct |
12 |
Correct |
102 ms |
5632 KB |
Output is correct |
13 |
Correct |
101 ms |
5824 KB |
Output is correct |
14 |
Correct |
100 ms |
5740 KB |
Output is correct |
15 |
Correct |
107 ms |
5848 KB |
Output is correct |
16 |
Correct |
114 ms |
5636 KB |
Output is correct |
17 |
Correct |
99 ms |
5748 KB |
Output is correct |
18 |
Correct |
1070 ms |
53204 KB |
Output is correct |
19 |
Correct |
1046 ms |
53420 KB |
Output is correct |
20 |
Correct |
1029 ms |
53348 KB |
Output is correct |
21 |
Correct |
99 ms |
5648 KB |
Output is correct |
22 |
Correct |
110 ms |
5824 KB |
Output is correct |
23 |
Correct |
347 ms |
20140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
108 ms |
5864 KB |
Output is correct |
3 |
Correct |
102 ms |
5724 KB |
Output is correct |
4 |
Correct |
999 ms |
53312 KB |
Output is correct |
5 |
Correct |
97 ms |
5668 KB |
Output is correct |
6 |
Correct |
97 ms |
5728 KB |
Output is correct |
7 |
Correct |
95 ms |
5820 KB |
Output is correct |
8 |
Correct |
99 ms |
5812 KB |
Output is correct |
9 |
Correct |
105 ms |
5668 KB |
Output is correct |
10 |
Correct |
100 ms |
5724 KB |
Output is correct |
11 |
Correct |
126 ms |
5588 KB |
Output is correct |
12 |
Correct |
100 ms |
5588 KB |
Output is correct |
13 |
Correct |
96 ms |
5788 KB |
Output is correct |
14 |
Correct |
1047 ms |
53352 KB |
Output is correct |
15 |
Correct |
106 ms |
5812 KB |
Output is correct |
16 |
Correct |
1050 ms |
53256 KB |
Output is correct |
17 |
Correct |
1039 ms |
53564 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
11 ms |
1368 KB |
Output is correct |
3 |
Correct |
10 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
10 ms |
1116 KB |
Output is correct |
17 |
Correct |
99 ms |
5804 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
528 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
717 ms |
41188 KB |
Output is correct |
29 |
Correct |
1 ms |
504 KB |
Output is correct |
30 |
Correct |
1078 ms |
53148 KB |
Output is correct |
31 |
Correct |
1006 ms |
53668 KB |
Output is correct |
32 |
Correct |
1004 ms |
53232 KB |
Output is correct |
33 |
Correct |
1 ms |
504 KB |
Output is correct |
34 |
Correct |
1031 ms |
53460 KB |
Output is correct |
35 |
Correct |
1043 ms |
53484 KB |
Output is correct |
36 |
Correct |
1267 ms |
53548 KB |
Output is correct |
37 |
Correct |
1004 ms |
53356 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
99 ms |
5756 KB |
Output is correct |
40 |
Correct |
114 ms |
5936 KB |
Output is correct |
41 |
Correct |
105 ms |
5680 KB |
Output is correct |
42 |
Correct |
98 ms |
5820 KB |
Output is correct |
43 |
Correct |
100 ms |
5792 KB |
Output is correct |
44 |
Correct |
109 ms |
5620 KB |
Output is correct |
45 |
Correct |
102 ms |
5632 KB |
Output is correct |
46 |
Correct |
101 ms |
5824 KB |
Output is correct |
47 |
Correct |
100 ms |
5740 KB |
Output is correct |
48 |
Correct |
107 ms |
5848 KB |
Output is correct |
49 |
Correct |
114 ms |
5636 KB |
Output is correct |
50 |
Correct |
99 ms |
5748 KB |
Output is correct |
51 |
Correct |
1070 ms |
53204 KB |
Output is correct |
52 |
Correct |
1046 ms |
53420 KB |
Output is correct |
53 |
Correct |
1029 ms |
53348 KB |
Output is correct |
54 |
Correct |
99 ms |
5648 KB |
Output is correct |
55 |
Correct |
110 ms |
5824 KB |
Output is correct |
56 |
Correct |
347 ms |
20140 KB |
Output is correct |
57 |
Correct |
1 ms |
344 KB |
Output is correct |
58 |
Correct |
108 ms |
5864 KB |
Output is correct |
59 |
Correct |
102 ms |
5724 KB |
Output is correct |
60 |
Correct |
999 ms |
53312 KB |
Output is correct |
61 |
Correct |
97 ms |
5668 KB |
Output is correct |
62 |
Correct |
97 ms |
5728 KB |
Output is correct |
63 |
Correct |
95 ms |
5820 KB |
Output is correct |
64 |
Correct |
99 ms |
5812 KB |
Output is correct |
65 |
Correct |
105 ms |
5668 KB |
Output is correct |
66 |
Correct |
100 ms |
5724 KB |
Output is correct |
67 |
Correct |
126 ms |
5588 KB |
Output is correct |
68 |
Correct |
100 ms |
5588 KB |
Output is correct |
69 |
Correct |
96 ms |
5788 KB |
Output is correct |
70 |
Correct |
1047 ms |
53352 KB |
Output is correct |
71 |
Correct |
106 ms |
5812 KB |
Output is correct |
72 |
Correct |
1050 ms |
53256 KB |
Output is correct |
73 |
Correct |
1039 ms |
53564 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
1 ms |
348 KB |
Output is correct |
77 |
Correct |
1 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
10 ms |
1076 KB |
Output is correct |
80 |
Correct |
1016 ms |
53888 KB |
Output is correct |
81 |
Correct |
1006 ms |
53380 KB |
Output is correct |
82 |
Correct |
1481 ms |
53480 KB |
Output is correct |
83 |
Correct |
1016 ms |
53196 KB |
Output is correct |
84 |
Correct |
983 ms |
53404 KB |
Output is correct |
85 |
Correct |
995 ms |
53156 KB |
Output is correct |
86 |
Correct |
330 ms |
20096 KB |
Output is correct |
87 |
Correct |
1 ms |
344 KB |
Output is correct |