#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n, A, B;
cin >> n >> A >> B;
int D = A / __gcd(A, B + 1);
int M = B * D;
vector <pair <int, int> > a;
while (n--) {
int l, r;
cin >> l >> r;
if (l / M == r / M) {
a.push_back({l % M, r % M});
continue;
}
int l1 = ((l + M - 1) / M) * M;
int r1 = (r / M) * M - 1;
int c = 0;
if (l1 <= r1) {
cout << M << '\n';
exit(0);
}
// [l % B; B - 1]
// [0; r % B]
int tl = r % M, tr = l % M;
if (tl < tr) {
a.push_back({0, tl});
a.push_back({tr, M - 1});
}
else {
cout << M << '\n';
exit(0);
}
}
int ans = 0;
vector <pair <int, int> > sc;
for (auto e : a) {
sc.push_back({e.first, 1});
sc.push_back({e.second + 1, -1});
}
sort(sc.begin(), sc.end());
int b = 0;
for (int i = 0; i + 1 < (int)sc.size(); ++i) {
b += sc[i].second;
if (b) ans += sc[i + 1].first - sc[i].first;
}
cout << ans << '\n';
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:27:13: warning: unused variable 'c' [-Wunused-variable]
int c = 0;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1268 KB |
Output is correct |
3 |
Correct |
10 ms |
1268 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
1300 KB |
Output is correct |
17 |
Correct |
88 ms |
6244 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
560 ms |
51464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
774 ms |
49944 KB |
Output is correct |
3 |
Correct |
840 ms |
50000 KB |
Output is correct |
4 |
Correct |
788 ms |
49864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
774 ms |
49944 KB |
Output is correct |
3 |
Correct |
840 ms |
50000 KB |
Output is correct |
4 |
Correct |
788 ms |
49864 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
799 ms |
49796 KB |
Output is correct |
7 |
Correct |
771 ms |
50008 KB |
Output is correct |
8 |
Correct |
787 ms |
50012 KB |
Output is correct |
9 |
Correct |
885 ms |
49860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
774 ms |
49944 KB |
Output is correct |
3 |
Correct |
840 ms |
50000 KB |
Output is correct |
4 |
Correct |
788 ms |
49864 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
76 ms |
9828 KB |
Output is correct |
7 |
Correct |
80 ms |
9828 KB |
Output is correct |
8 |
Correct |
78 ms |
9828 KB |
Output is correct |
9 |
Correct |
81 ms |
9956 KB |
Output is correct |
10 |
Correct |
76 ms |
9836 KB |
Output is correct |
11 |
Correct |
80 ms |
9828 KB |
Output is correct |
12 |
Correct |
77 ms |
9856 KB |
Output is correct |
13 |
Correct |
82 ms |
9828 KB |
Output is correct |
14 |
Correct |
79 ms |
9800 KB |
Output is correct |
15 |
Correct |
89 ms |
9288 KB |
Output is correct |
16 |
Correct |
88 ms |
9172 KB |
Output is correct |
17 |
Correct |
80 ms |
9324 KB |
Output is correct |
18 |
Correct |
815 ms |
49936 KB |
Output is correct |
19 |
Correct |
766 ms |
49880 KB |
Output is correct |
20 |
Correct |
913 ms |
49840 KB |
Output is correct |
21 |
Correct |
89 ms |
9712 KB |
Output is correct |
22 |
Correct |
72 ms |
9804 KB |
Output is correct |
23 |
Correct |
237 ms |
28148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
86 ms |
9500 KB |
Output is correct |
3 |
Correct |
91 ms |
9448 KB |
Output is correct |
4 |
Correct |
998 ms |
49964 KB |
Output is correct |
5 |
Correct |
85 ms |
9576 KB |
Output is correct |
6 |
Correct |
86 ms |
9544 KB |
Output is correct |
7 |
Correct |
85 ms |
9656 KB |
Output is correct |
8 |
Correct |
88 ms |
9828 KB |
Output is correct |
9 |
Correct |
83 ms |
9900 KB |
Output is correct |
10 |
Correct |
90 ms |
9604 KB |
Output is correct |
11 |
Correct |
86 ms |
9316 KB |
Output is correct |
12 |
Correct |
79 ms |
9280 KB |
Output is correct |
13 |
Correct |
89 ms |
9320 KB |
Output is correct |
14 |
Correct |
900 ms |
50028 KB |
Output is correct |
15 |
Correct |
90 ms |
8844 KB |
Output is correct |
16 |
Correct |
751 ms |
49940 KB |
Output is correct |
17 |
Correct |
789 ms |
50052 KB |
Output is correct |
18 |
Correct |
2 ms |
252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1268 KB |
Output is correct |
3 |
Correct |
10 ms |
1268 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
1300 KB |
Output is correct |
17 |
Correct |
88 ms |
6244 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
424 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
560 ms |
51464 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
774 ms |
49944 KB |
Output is correct |
31 |
Correct |
840 ms |
50000 KB |
Output is correct |
32 |
Correct |
788 ms |
49864 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
799 ms |
49796 KB |
Output is correct |
35 |
Correct |
771 ms |
50008 KB |
Output is correct |
36 |
Correct |
787 ms |
50012 KB |
Output is correct |
37 |
Correct |
885 ms |
49860 KB |
Output is correct |
38 |
Correct |
2 ms |
380 KB |
Output is correct |
39 |
Correct |
76 ms |
9828 KB |
Output is correct |
40 |
Correct |
80 ms |
9828 KB |
Output is correct |
41 |
Correct |
78 ms |
9828 KB |
Output is correct |
42 |
Correct |
81 ms |
9956 KB |
Output is correct |
43 |
Correct |
76 ms |
9836 KB |
Output is correct |
44 |
Correct |
80 ms |
9828 KB |
Output is correct |
45 |
Correct |
77 ms |
9856 KB |
Output is correct |
46 |
Correct |
82 ms |
9828 KB |
Output is correct |
47 |
Correct |
79 ms |
9800 KB |
Output is correct |
48 |
Correct |
89 ms |
9288 KB |
Output is correct |
49 |
Correct |
88 ms |
9172 KB |
Output is correct |
50 |
Correct |
80 ms |
9324 KB |
Output is correct |
51 |
Correct |
815 ms |
49936 KB |
Output is correct |
52 |
Correct |
766 ms |
49880 KB |
Output is correct |
53 |
Correct |
913 ms |
49840 KB |
Output is correct |
54 |
Correct |
89 ms |
9712 KB |
Output is correct |
55 |
Correct |
72 ms |
9804 KB |
Output is correct |
56 |
Correct |
237 ms |
28148 KB |
Output is correct |
57 |
Correct |
2 ms |
256 KB |
Output is correct |
58 |
Correct |
86 ms |
9500 KB |
Output is correct |
59 |
Correct |
91 ms |
9448 KB |
Output is correct |
60 |
Correct |
998 ms |
49964 KB |
Output is correct |
61 |
Correct |
85 ms |
9576 KB |
Output is correct |
62 |
Correct |
86 ms |
9544 KB |
Output is correct |
63 |
Correct |
85 ms |
9656 KB |
Output is correct |
64 |
Correct |
88 ms |
9828 KB |
Output is correct |
65 |
Correct |
83 ms |
9900 KB |
Output is correct |
66 |
Correct |
90 ms |
9604 KB |
Output is correct |
67 |
Correct |
86 ms |
9316 KB |
Output is correct |
68 |
Correct |
79 ms |
9280 KB |
Output is correct |
69 |
Correct |
89 ms |
9320 KB |
Output is correct |
70 |
Correct |
900 ms |
50028 KB |
Output is correct |
71 |
Correct |
90 ms |
8844 KB |
Output is correct |
72 |
Correct |
751 ms |
49940 KB |
Output is correct |
73 |
Correct |
789 ms |
50052 KB |
Output is correct |
74 |
Correct |
2 ms |
252 KB |
Output is correct |
75 |
Correct |
2 ms |
464 KB |
Output is correct |
76 |
Correct |
2 ms |
376 KB |
Output is correct |
77 |
Correct |
2 ms |
376 KB |
Output is correct |
78 |
Correct |
3 ms |
376 KB |
Output is correct |
79 |
Correct |
9 ms |
1504 KB |
Output is correct |
80 |
Correct |
994 ms |
50068 KB |
Output is correct |
81 |
Correct |
988 ms |
49964 KB |
Output is correct |
82 |
Correct |
883 ms |
49900 KB |
Output is correct |
83 |
Correct |
880 ms |
49944 KB |
Output is correct |
84 |
Correct |
891 ms |
49928 KB |
Output is correct |
85 |
Correct |
878 ms |
50016 KB |
Output is correct |
86 |
Correct |
233 ms |
27588 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |