#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a, b;
pair<ll, ll> t[2000005];
stack<pair<ll, ll>> st;
ll gcd(ll a, ll b) {
if(b == 0) return a;
else return gcd(b, a%b);
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> a >> b;
ll g = gcd(a,b+1);
ll k = a/g;
ll tlimit = k * b;
int idx = 0;
for(int i = 0; i < n; i++) {
ll l, r; cin >> l >> r;
if(l/tlimit == r/tlimit) {
t[idx++] = make_pair(l%tlimit, r%tlimit);
} else if(l/tlimit == (r/tlimit - 1)) {
t[idx++] = make_pair(l%tlimit, tlimit-1);
t[idx++] = make_pair(0ll, r%tlimit);
} else {
t[idx++] = make_pair(0ll, tlimit-1);
}
}
sort(t, t+idx);
st.push(t[0]);
for(int i = 1; i < idx; i++) {
if(st.top().second < t[i].first)
st.push(t[i]);
else if(st.top().second < t[i].second)
st.top().second = t[i].second;
}
ll ans = 0;
while(!st.empty()) {
ans += 1ll * (st.top().second - st.top().first + 1);
st.pop();
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
768 KB |
Output is correct |
3 |
Correct |
10 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
9 ms |
768 KB |
Output is correct |
17 |
Correct |
58 ms |
3836 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
367 ms |
16188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
508 ms |
32428 KB |
Output is correct |
3 |
Correct |
510 ms |
32556 KB |
Output is correct |
4 |
Correct |
489 ms |
32428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
508 ms |
32428 KB |
Output is correct |
3 |
Correct |
510 ms |
32556 KB |
Output is correct |
4 |
Correct |
489 ms |
32428 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
483 ms |
32456 KB |
Output is correct |
7 |
Correct |
495 ms |
32556 KB |
Output is correct |
8 |
Correct |
500 ms |
32428 KB |
Output is correct |
9 |
Correct |
656 ms |
32640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
508 ms |
32428 KB |
Output is correct |
3 |
Correct |
510 ms |
32556 KB |
Output is correct |
4 |
Correct |
489 ms |
32428 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
55 ms |
3704 KB |
Output is correct |
7 |
Correct |
59 ms |
3704 KB |
Output is correct |
8 |
Correct |
53 ms |
3704 KB |
Output is correct |
9 |
Correct |
75 ms |
3716 KB |
Output is correct |
10 |
Correct |
52 ms |
3644 KB |
Output is correct |
11 |
Correct |
53 ms |
3704 KB |
Output is correct |
12 |
Correct |
52 ms |
3704 KB |
Output is correct |
13 |
Correct |
54 ms |
3704 KB |
Output is correct |
14 |
Correct |
52 ms |
3704 KB |
Output is correct |
15 |
Correct |
57 ms |
3704 KB |
Output is correct |
16 |
Correct |
55 ms |
3704 KB |
Output is correct |
17 |
Correct |
54 ms |
3704 KB |
Output is correct |
18 |
Correct |
501 ms |
32684 KB |
Output is correct |
19 |
Correct |
493 ms |
32428 KB |
Output is correct |
20 |
Correct |
547 ms |
32444 KB |
Output is correct |
21 |
Correct |
58 ms |
3704 KB |
Output is correct |
22 |
Correct |
56 ms |
3704 KB |
Output is correct |
23 |
Correct |
158 ms |
5752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
56 ms |
3576 KB |
Output is correct |
3 |
Correct |
59 ms |
3704 KB |
Output is correct |
4 |
Correct |
576 ms |
32556 KB |
Output is correct |
5 |
Correct |
56 ms |
3704 KB |
Output is correct |
6 |
Correct |
57 ms |
3704 KB |
Output is correct |
7 |
Correct |
57 ms |
3704 KB |
Output is correct |
8 |
Correct |
56 ms |
3704 KB |
Output is correct |
9 |
Correct |
55 ms |
3704 KB |
Output is correct |
10 |
Correct |
56 ms |
3704 KB |
Output is correct |
11 |
Correct |
56 ms |
3704 KB |
Output is correct |
12 |
Correct |
50 ms |
3708 KB |
Output is correct |
13 |
Correct |
56 ms |
3704 KB |
Output is correct |
14 |
Correct |
538 ms |
32428 KB |
Output is correct |
15 |
Correct |
56 ms |
3448 KB |
Output is correct |
16 |
Correct |
499 ms |
32564 KB |
Output is correct |
17 |
Correct |
475 ms |
32428 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
768 KB |
Output is correct |
3 |
Correct |
10 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
9 ms |
768 KB |
Output is correct |
17 |
Correct |
58 ms |
3836 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
367 ms |
16188 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
508 ms |
32428 KB |
Output is correct |
31 |
Correct |
510 ms |
32556 KB |
Output is correct |
32 |
Correct |
489 ms |
32428 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
483 ms |
32456 KB |
Output is correct |
35 |
Correct |
495 ms |
32556 KB |
Output is correct |
36 |
Correct |
500 ms |
32428 KB |
Output is correct |
37 |
Correct |
656 ms |
32640 KB |
Output is correct |
38 |
Correct |
4 ms |
256 KB |
Output is correct |
39 |
Correct |
55 ms |
3704 KB |
Output is correct |
40 |
Correct |
59 ms |
3704 KB |
Output is correct |
41 |
Correct |
53 ms |
3704 KB |
Output is correct |
42 |
Correct |
75 ms |
3716 KB |
Output is correct |
43 |
Correct |
52 ms |
3644 KB |
Output is correct |
44 |
Correct |
53 ms |
3704 KB |
Output is correct |
45 |
Correct |
52 ms |
3704 KB |
Output is correct |
46 |
Correct |
54 ms |
3704 KB |
Output is correct |
47 |
Correct |
52 ms |
3704 KB |
Output is correct |
48 |
Correct |
57 ms |
3704 KB |
Output is correct |
49 |
Correct |
55 ms |
3704 KB |
Output is correct |
50 |
Correct |
54 ms |
3704 KB |
Output is correct |
51 |
Correct |
501 ms |
32684 KB |
Output is correct |
52 |
Correct |
493 ms |
32428 KB |
Output is correct |
53 |
Correct |
547 ms |
32444 KB |
Output is correct |
54 |
Correct |
58 ms |
3704 KB |
Output is correct |
55 |
Correct |
56 ms |
3704 KB |
Output is correct |
56 |
Correct |
158 ms |
5752 KB |
Output is correct |
57 |
Correct |
5 ms |
384 KB |
Output is correct |
58 |
Correct |
56 ms |
3576 KB |
Output is correct |
59 |
Correct |
59 ms |
3704 KB |
Output is correct |
60 |
Correct |
576 ms |
32556 KB |
Output is correct |
61 |
Correct |
56 ms |
3704 KB |
Output is correct |
62 |
Correct |
57 ms |
3704 KB |
Output is correct |
63 |
Correct |
57 ms |
3704 KB |
Output is correct |
64 |
Correct |
56 ms |
3704 KB |
Output is correct |
65 |
Correct |
55 ms |
3704 KB |
Output is correct |
66 |
Correct |
56 ms |
3704 KB |
Output is correct |
67 |
Correct |
56 ms |
3704 KB |
Output is correct |
68 |
Correct |
50 ms |
3708 KB |
Output is correct |
69 |
Correct |
56 ms |
3704 KB |
Output is correct |
70 |
Correct |
538 ms |
32428 KB |
Output is correct |
71 |
Correct |
56 ms |
3448 KB |
Output is correct |
72 |
Correct |
499 ms |
32564 KB |
Output is correct |
73 |
Correct |
475 ms |
32428 KB |
Output is correct |
74 |
Correct |
5 ms |
384 KB |
Output is correct |
75 |
Correct |
4 ms |
384 KB |
Output is correct |
76 |
Correct |
4 ms |
384 KB |
Output is correct |
77 |
Correct |
5 ms |
384 KB |
Output is correct |
78 |
Correct |
4 ms |
384 KB |
Output is correct |
79 |
Correct |
9 ms |
1024 KB |
Output is correct |
80 |
Correct |
612 ms |
69932 KB |
Output is correct |
81 |
Correct |
568 ms |
69676 KB |
Output is correct |
82 |
Correct |
548 ms |
69548 KB |
Output is correct |
83 |
Correct |
561 ms |
69792 KB |
Output is correct |
84 |
Correct |
557 ms |
69668 KB |
Output is correct |
85 |
Correct |
540 ms |
69668 KB |
Output is correct |
86 |
Correct |
156 ms |
18296 KB |
Output is correct |
87 |
Correct |
5 ms |
384 KB |
Output is correct |