#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int n;
long long a,b;
map<long long,int> ma;
set<long long> s;
int res[N];
vector<pair<long long,long long> > in;
long long rng[N],ans;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> a >> b;
a/=__gcd(a,b+1);
if(a>1e18/b) a = (1e18+2),b = 1;
for(int i = 0;i < n;i++)
{
long long x,y;
cin >> x >> y;
if(y-x+1LL>=a*b){ cout << a*b; return 0; }
y++;
x%=(a*b),y%=(a*b);
if(y<x) in.push_back({0LL,y}),in.push_back({x,a*b});
else in.push_back({x,y});
s.insert(x),s.insert(y);
}
s.insert(0),s.insert(a*b);
long long prev = 0;
int id = 0;
for(auto x : s) ma[x] = ++id,rng[id-1] = x-prev,prev = x;
for(auto x : in) res[ma[x.first]]++,res[ma[x.second]]--;
for(int i = 1;i < N;i++) res[i]+=res[i-1];
for(int i = 1;i < N;i++) if(res[i]) ans+=rng[i];
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
26 ms |
9980 KB |
Output is correct |
3 |
Correct |
27 ms |
9972 KB |
Output is correct |
4 |
Correct |
15 ms |
8192 KB |
Output is correct |
5 |
Correct |
15 ms |
8192 KB |
Output is correct |
6 |
Correct |
15 ms |
8192 KB |
Output is correct |
7 |
Correct |
15 ms |
8192 KB |
Output is correct |
8 |
Correct |
17 ms |
8192 KB |
Output is correct |
9 |
Correct |
15 ms |
8192 KB |
Output is correct |
10 |
Correct |
15 ms |
8192 KB |
Output is correct |
11 |
Correct |
15 ms |
8192 KB |
Output is correct |
12 |
Correct |
15 ms |
8192 KB |
Output is correct |
13 |
Correct |
15 ms |
8192 KB |
Output is correct |
14 |
Correct |
15 ms |
8192 KB |
Output is correct |
15 |
Correct |
16 ms |
8192 KB |
Output is correct |
16 |
Correct |
26 ms |
9952 KB |
Output is correct |
17 |
Correct |
138 ms |
25188 KB |
Output is correct |
18 |
Correct |
15 ms |
8192 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 |
16 ms |
8192 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
15 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
16 ms |
8448 KB |
Output is correct |
3 |
Correct |
17 ms |
8320 KB |
Output is correct |
4 |
Correct |
17 ms |
8448 KB |
Output is correct |
5 |
Correct |
388 ms |
25028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
1338 ms |
141568 KB |
Output is correct |
3 |
Correct |
1340 ms |
141700 KB |
Output is correct |
4 |
Correct |
1451 ms |
178572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
1338 ms |
141568 KB |
Output is correct |
3 |
Correct |
1340 ms |
141700 KB |
Output is correct |
4 |
Correct |
1451 ms |
178572 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
1445 ms |
178684 KB |
Output is correct |
7 |
Correct |
1389 ms |
178604 KB |
Output is correct |
8 |
Correct |
1372 ms |
178476 KB |
Output is correct |
9 |
Correct |
1492 ms |
178540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
1338 ms |
141568 KB |
Output is correct |
3 |
Correct |
1340 ms |
141700 KB |
Output is correct |
4 |
Correct |
1451 ms |
178572 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
134 ms |
25188 KB |
Output is correct |
7 |
Correct |
131 ms |
25320 KB |
Output is correct |
8 |
Correct |
133 ms |
25256 KB |
Output is correct |
9 |
Correct |
143 ms |
25328 KB |
Output is correct |
10 |
Correct |
139 ms |
25188 KB |
Output is correct |
11 |
Correct |
135 ms |
25240 KB |
Output is correct |
12 |
Correct |
128 ms |
25188 KB |
Output is correct |
13 |
Correct |
146 ms |
25296 KB |
Output is correct |
14 |
Correct |
129 ms |
25188 KB |
Output is correct |
15 |
Correct |
152 ms |
25188 KB |
Output is correct |
16 |
Correct |
137 ms |
25188 KB |
Output is correct |
17 |
Correct |
135 ms |
25188 KB |
Output is correct |
18 |
Correct |
1378 ms |
178412 KB |
Output is correct |
19 |
Correct |
1399 ms |
178740 KB |
Output is correct |
20 |
Correct |
1438 ms |
178596 KB |
Output is correct |
21 |
Correct |
134 ms |
25444 KB |
Output is correct |
22 |
Correct |
158 ms |
25192 KB |
Output is correct |
23 |
Correct |
184 ms |
26232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
148 ms |
25268 KB |
Output is correct |
3 |
Correct |
137 ms |
25188 KB |
Output is correct |
4 |
Correct |
1393 ms |
141884 KB |
Output is correct |
5 |
Correct |
142 ms |
25320 KB |
Output is correct |
6 |
Correct |
148 ms |
25192 KB |
Output is correct |
7 |
Correct |
137 ms |
25188 KB |
Output is correct |
8 |
Correct |
143 ms |
25188 KB |
Output is correct |
9 |
Correct |
141 ms |
25404 KB |
Output is correct |
10 |
Correct |
140 ms |
25188 KB |
Output is correct |
11 |
Correct |
134 ms |
25188 KB |
Output is correct |
12 |
Correct |
144 ms |
25188 KB |
Output is correct |
13 |
Correct |
142 ms |
25228 KB |
Output is correct |
14 |
Correct |
1400 ms |
142012 KB |
Output is correct |
15 |
Correct |
133 ms |
25212 KB |
Output is correct |
16 |
Correct |
1332 ms |
178460 KB |
Output is correct |
17 |
Correct |
1363 ms |
178596 KB |
Output is correct |
18 |
Correct |
22 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
26 ms |
9980 KB |
Output is correct |
3 |
Correct |
27 ms |
9972 KB |
Output is correct |
4 |
Correct |
15 ms |
8192 KB |
Output is correct |
5 |
Correct |
15 ms |
8192 KB |
Output is correct |
6 |
Correct |
15 ms |
8192 KB |
Output is correct |
7 |
Correct |
15 ms |
8192 KB |
Output is correct |
8 |
Correct |
17 ms |
8192 KB |
Output is correct |
9 |
Correct |
15 ms |
8192 KB |
Output is correct |
10 |
Correct |
15 ms |
8192 KB |
Output is correct |
11 |
Correct |
15 ms |
8192 KB |
Output is correct |
12 |
Correct |
15 ms |
8192 KB |
Output is correct |
13 |
Correct |
15 ms |
8192 KB |
Output is correct |
14 |
Correct |
15 ms |
8192 KB |
Output is correct |
15 |
Correct |
16 ms |
8192 KB |
Output is correct |
16 |
Correct |
26 ms |
9952 KB |
Output is correct |
17 |
Correct |
138 ms |
25188 KB |
Output is correct |
18 |
Correct |
15 ms |
8192 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
16 ms |
8192 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
15 ms |
8192 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
16 ms |
8448 KB |
Output is correct |
26 |
Correct |
17 ms |
8320 KB |
Output is correct |
27 |
Correct |
17 ms |
8448 KB |
Output is correct |
28 |
Correct |
388 ms |
25028 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
1338 ms |
141568 KB |
Output is correct |
31 |
Correct |
1340 ms |
141700 KB |
Output is correct |
32 |
Correct |
1451 ms |
178572 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
1445 ms |
178684 KB |
Output is correct |
35 |
Correct |
1389 ms |
178604 KB |
Output is correct |
36 |
Correct |
1372 ms |
178476 KB |
Output is correct |
37 |
Correct |
1492 ms |
178540 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
134 ms |
25188 KB |
Output is correct |
40 |
Correct |
131 ms |
25320 KB |
Output is correct |
41 |
Correct |
133 ms |
25256 KB |
Output is correct |
42 |
Correct |
143 ms |
25328 KB |
Output is correct |
43 |
Correct |
139 ms |
25188 KB |
Output is correct |
44 |
Correct |
135 ms |
25240 KB |
Output is correct |
45 |
Correct |
128 ms |
25188 KB |
Output is correct |
46 |
Correct |
146 ms |
25296 KB |
Output is correct |
47 |
Correct |
129 ms |
25188 KB |
Output is correct |
48 |
Correct |
152 ms |
25188 KB |
Output is correct |
49 |
Correct |
137 ms |
25188 KB |
Output is correct |
50 |
Correct |
135 ms |
25188 KB |
Output is correct |
51 |
Correct |
1378 ms |
178412 KB |
Output is correct |
52 |
Correct |
1399 ms |
178740 KB |
Output is correct |
53 |
Correct |
1438 ms |
178596 KB |
Output is correct |
54 |
Correct |
134 ms |
25444 KB |
Output is correct |
55 |
Correct |
158 ms |
25192 KB |
Output is correct |
56 |
Correct |
184 ms |
26232 KB |
Output is correct |
57 |
Correct |
5 ms |
384 KB |
Output is correct |
58 |
Correct |
148 ms |
25268 KB |
Output is correct |
59 |
Correct |
137 ms |
25188 KB |
Output is correct |
60 |
Correct |
1393 ms |
141884 KB |
Output is correct |
61 |
Correct |
142 ms |
25320 KB |
Output is correct |
62 |
Correct |
148 ms |
25192 KB |
Output is correct |
63 |
Correct |
137 ms |
25188 KB |
Output is correct |
64 |
Correct |
143 ms |
25188 KB |
Output is correct |
65 |
Correct |
141 ms |
25404 KB |
Output is correct |
66 |
Correct |
140 ms |
25188 KB |
Output is correct |
67 |
Correct |
134 ms |
25188 KB |
Output is correct |
68 |
Correct |
144 ms |
25188 KB |
Output is correct |
69 |
Correct |
142 ms |
25228 KB |
Output is correct |
70 |
Correct |
1400 ms |
142012 KB |
Output is correct |
71 |
Correct |
133 ms |
25212 KB |
Output is correct |
72 |
Correct |
1332 ms |
178460 KB |
Output is correct |
73 |
Correct |
1363 ms |
178596 KB |
Output is correct |
74 |
Correct |
22 ms |
8192 KB |
Output is correct |
75 |
Correct |
5 ms |
384 KB |
Output is correct |
76 |
Correct |
16 ms |
8192 KB |
Output is correct |
77 |
Correct |
15 ms |
8192 KB |
Output is correct |
78 |
Correct |
15 ms |
8192 KB |
Output is correct |
79 |
Correct |
34 ms |
9972 KB |
Output is correct |
80 |
Correct |
1540 ms |
178188 KB |
Output is correct |
81 |
Correct |
1498 ms |
178488 KB |
Output is correct |
82 |
Correct |
1518 ms |
178428 KB |
Output is correct |
83 |
Correct |
1518 ms |
178388 KB |
Output is correct |
84 |
Correct |
1533 ms |
178424 KB |
Output is correct |
85 |
Correct |
1452 ms |
178184 KB |
Output is correct |
86 |
Correct |
189 ms |
26196 KB |
Output is correct |
87 |
Correct |
19 ms |
8192 KB |
Output is correct |