#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
const ll inf=2e18;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, A, B; cin >> n >> A >> B, A=A/__gcd(A, B+1);
vector <pll> range;
if (A>inf/B)
{
range.resize(n);
for (pll &i:range) cin >> i.fi >> i.se;
}
else
{
ll M=A*B;
for (ll i=0; i<n; i++)
{
ll l, r; cin >> l >> r;
ll bl=l/M, br=r/M;
if (bl==br) range.pb({l%M, r%M});
else if (bl+1==br) range.pb({l%M, M-1}), range.pb({0, r%M});
else range.pb({0, M-1});
}
}
vector <ll> cx;
for (pll i:range) cx.pb(i.fi), cx.pb(i.se+1);
sort(cx.begin(), cx.end()), cx.resize(unique(cx.begin(), cx.end())-cx.begin());
vector <ll> sum(sz(cx), 0);
for (pll i:range)
{
sum[lower_bound(cx.begin(), cx.end(), i.fi)-cx.begin()]++;
sum[lower_bound(cx.begin(), cx.end(), i.se+1)-cx.begin()]--;
}
ll ans=0;
for (ll i=0, crr=0; i<sz(cx); crr+=sum[i], ans+=(!!crr)*(cx[i+1]-cx[i]), i++) {}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
5 ms |
1244 KB |
Output is correct |
3 |
Correct |
5 ms |
1216 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
1 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 |
1248 KB |
Output is correct |
17 |
Correct |
53 ms |
8644 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
452 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 |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
230 ms |
66088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
457 ms |
78548 KB |
Output is correct |
3 |
Correct |
478 ms |
78808 KB |
Output is correct |
4 |
Correct |
445 ms |
80260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
457 ms |
78548 KB |
Output is correct |
3 |
Correct |
478 ms |
78808 KB |
Output is correct |
4 |
Correct |
445 ms |
80260 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
467 ms |
79168 KB |
Output is correct |
7 |
Correct |
455 ms |
79896 KB |
Output is correct |
8 |
Correct |
467 ms |
80060 KB |
Output is correct |
9 |
Correct |
502 ms |
78080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
457 ms |
78548 KB |
Output is correct |
3 |
Correct |
478 ms |
78808 KB |
Output is correct |
4 |
Correct |
445 ms |
80260 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
44 ms |
8800 KB |
Output is correct |
7 |
Correct |
46 ms |
8664 KB |
Output is correct |
8 |
Correct |
41 ms |
8648 KB |
Output is correct |
9 |
Correct |
47 ms |
8712 KB |
Output is correct |
10 |
Correct |
42 ms |
8636 KB |
Output is correct |
11 |
Correct |
50 ms |
8776 KB |
Output is correct |
12 |
Correct |
44 ms |
8652 KB |
Output is correct |
13 |
Correct |
59 ms |
8648 KB |
Output is correct |
14 |
Correct |
42 ms |
8660 KB |
Output is correct |
15 |
Correct |
50 ms |
8644 KB |
Output is correct |
16 |
Correct |
56 ms |
9020 KB |
Output is correct |
17 |
Correct |
45 ms |
8776 KB |
Output is correct |
18 |
Correct |
483 ms |
80152 KB |
Output is correct |
19 |
Correct |
444 ms |
78116 KB |
Output is correct |
20 |
Correct |
522 ms |
78008 KB |
Output is correct |
21 |
Correct |
53 ms |
8912 KB |
Output is correct |
22 |
Correct |
40 ms |
8912 KB |
Output is correct |
23 |
Correct |
99 ms |
32452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
54 ms |
8652 KB |
Output is correct |
3 |
Correct |
50 ms |
8644 KB |
Output is correct |
4 |
Correct |
534 ms |
78588 KB |
Output is correct |
5 |
Correct |
53 ms |
8648 KB |
Output is correct |
6 |
Correct |
50 ms |
8648 KB |
Output is correct |
7 |
Correct |
49 ms |
8652 KB |
Output is correct |
8 |
Correct |
55 ms |
8644 KB |
Output is correct |
9 |
Correct |
48 ms |
8648 KB |
Output is correct |
10 |
Correct |
52 ms |
8652 KB |
Output is correct |
11 |
Correct |
50 ms |
8656 KB |
Output is correct |
12 |
Correct |
43 ms |
8652 KB |
Output is correct |
13 |
Correct |
51 ms |
8648 KB |
Output is correct |
14 |
Correct |
516 ms |
79736 KB |
Output is correct |
15 |
Correct |
53 ms |
8652 KB |
Output is correct |
16 |
Correct |
440 ms |
77824 KB |
Output is correct |
17 |
Correct |
464 ms |
80560 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
5 ms |
1244 KB |
Output is correct |
3 |
Correct |
5 ms |
1216 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
1 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 |
1248 KB |
Output is correct |
17 |
Correct |
53 ms |
8644 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
452 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 |
600 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 |
230 ms |
66088 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
457 ms |
78548 KB |
Output is correct |
31 |
Correct |
478 ms |
78808 KB |
Output is correct |
32 |
Correct |
445 ms |
80260 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
467 ms |
79168 KB |
Output is correct |
35 |
Correct |
455 ms |
79896 KB |
Output is correct |
36 |
Correct |
467 ms |
80060 KB |
Output is correct |
37 |
Correct |
502 ms |
78080 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
44 ms |
8800 KB |
Output is correct |
40 |
Correct |
46 ms |
8664 KB |
Output is correct |
41 |
Correct |
41 ms |
8648 KB |
Output is correct |
42 |
Correct |
47 ms |
8712 KB |
Output is correct |
43 |
Correct |
42 ms |
8636 KB |
Output is correct |
44 |
Correct |
50 ms |
8776 KB |
Output is correct |
45 |
Correct |
44 ms |
8652 KB |
Output is correct |
46 |
Correct |
59 ms |
8648 KB |
Output is correct |
47 |
Correct |
42 ms |
8660 KB |
Output is correct |
48 |
Correct |
50 ms |
8644 KB |
Output is correct |
49 |
Correct |
56 ms |
9020 KB |
Output is correct |
50 |
Correct |
45 ms |
8776 KB |
Output is correct |
51 |
Correct |
483 ms |
80152 KB |
Output is correct |
52 |
Correct |
444 ms |
78116 KB |
Output is correct |
53 |
Correct |
522 ms |
78008 KB |
Output is correct |
54 |
Correct |
53 ms |
8912 KB |
Output is correct |
55 |
Correct |
40 ms |
8912 KB |
Output is correct |
56 |
Correct |
99 ms |
32452 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
54 ms |
8652 KB |
Output is correct |
59 |
Correct |
50 ms |
8644 KB |
Output is correct |
60 |
Correct |
534 ms |
78588 KB |
Output is correct |
61 |
Correct |
53 ms |
8648 KB |
Output is correct |
62 |
Correct |
50 ms |
8648 KB |
Output is correct |
63 |
Correct |
49 ms |
8652 KB |
Output is correct |
64 |
Correct |
55 ms |
8644 KB |
Output is correct |
65 |
Correct |
48 ms |
8648 KB |
Output is correct |
66 |
Correct |
52 ms |
8652 KB |
Output is correct |
67 |
Correct |
50 ms |
8656 KB |
Output is correct |
68 |
Correct |
43 ms |
8652 KB |
Output is correct |
69 |
Correct |
51 ms |
8648 KB |
Output is correct |
70 |
Correct |
516 ms |
79736 KB |
Output is correct |
71 |
Correct |
53 ms |
8652 KB |
Output is correct |
72 |
Correct |
440 ms |
77824 KB |
Output is correct |
73 |
Correct |
464 ms |
80560 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
344 KB |
Output is correct |
76 |
Correct |
0 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 |
1364 KB |
Output is correct |
80 |
Correct |
541 ms |
80148 KB |
Output is correct |
81 |
Correct |
565 ms |
77712 KB |
Output is correct |
82 |
Correct |
538 ms |
80564 KB |
Output is correct |
83 |
Correct |
523 ms |
79168 KB |
Output is correct |
84 |
Correct |
518 ms |
78796 KB |
Output is correct |
85 |
Correct |
541 ms |
79824 KB |
Output is correct |
86 |
Correct |
108 ms |
32880 KB |
Output is correct |
87 |
Correct |
0 ms |
348 KB |
Output is correct |