#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
const int MAXN = 4e6+10;
ll vals[MAXN];
pair<ll,ll> ranges[MAXN];
ll pref[MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; ll A,B; cin >> N >> A >> B;
ll C = A/gcd(A,B+1)*B;
int cnt = 0;
for(int i = 0;i<N;++i){
ll l,r; cin >> l >> r;
if(r-l+1 >= C){
cout << C << "\n";
return 0;
}
l %= C; r %= C;
if(l <= r){
ranges[++cnt] = make_pair(l,r);
}
else{
ranges[++cnt] = make_pair(l,C-1);
ranges[++cnt] = make_pair(0ll,r);
}
}
int m = 0;
for(int i = 1;i<=cnt;++i){
vals[++m] = ranges[i].f;
vals[++m] = ranges[i].s+1;
}
sort(vals+1,vals+m+1);
for(int i = 1;i<=cnt;++i){
int ind = lower_bound(vals+1,vals+m+1,ranges[i].f)-vals;
int ind2 = lower_bound(vals+1,vals+m+1,ranges[i].s+1)-vals;
++pref[ind]; --pref[ind2];
}
ll ans = 0ll;
for(int i = 1;i<=m;++i){
pref[i] += pref[i-1];
if(pref[i]){
ans += vals[i+1]-vals[i];
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
1116 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 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 |
4 ms |
1244 KB |
Output is correct |
17 |
Correct |
44 ms |
8788 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
224 ms |
72536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
404 ms |
84548 KB |
Output is correct |
3 |
Correct |
425 ms |
84504 KB |
Output is correct |
4 |
Correct |
420 ms |
84528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
404 ms |
84548 KB |
Output is correct |
3 |
Correct |
425 ms |
84504 KB |
Output is correct |
4 |
Correct |
420 ms |
84528 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
419 ms |
84516 KB |
Output is correct |
7 |
Correct |
399 ms |
84560 KB |
Output is correct |
8 |
Correct |
441 ms |
84596 KB |
Output is correct |
9 |
Correct |
484 ms |
84560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
404 ms |
84548 KB |
Output is correct |
3 |
Correct |
425 ms |
84504 KB |
Output is correct |
4 |
Correct |
420 ms |
84528 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
42 ms |
8752 KB |
Output is correct |
7 |
Correct |
42 ms |
8624 KB |
Output is correct |
8 |
Correct |
37 ms |
8788 KB |
Output is correct |
9 |
Correct |
40 ms |
8784 KB |
Output is correct |
10 |
Correct |
40 ms |
9048 KB |
Output is correct |
11 |
Correct |
41 ms |
8784 KB |
Output is correct |
12 |
Correct |
46 ms |
8844 KB |
Output is correct |
13 |
Correct |
47 ms |
9108 KB |
Output is correct |
14 |
Correct |
36 ms |
8796 KB |
Output is correct |
15 |
Correct |
44 ms |
8860 KB |
Output is correct |
16 |
Correct |
43 ms |
8844 KB |
Output is correct |
17 |
Correct |
39 ms |
8796 KB |
Output is correct |
18 |
Correct |
433 ms |
84560 KB |
Output is correct |
19 |
Correct |
396 ms |
84588 KB |
Output is correct |
20 |
Correct |
486 ms |
84588 KB |
Output is correct |
21 |
Correct |
45 ms |
8788 KB |
Output is correct |
22 |
Correct |
36 ms |
8784 KB |
Output is correct |
23 |
Correct |
96 ms |
28920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
42 ms |
8864 KB |
Output is correct |
3 |
Correct |
45 ms |
8664 KB |
Output is correct |
4 |
Correct |
480 ms |
84700 KB |
Output is correct |
5 |
Correct |
43 ms |
8856 KB |
Output is correct |
6 |
Correct |
44 ms |
8788 KB |
Output is correct |
7 |
Correct |
44 ms |
8784 KB |
Output is correct |
8 |
Correct |
45 ms |
8788 KB |
Output is correct |
9 |
Correct |
45 ms |
12372 KB |
Output is correct |
10 |
Correct |
44 ms |
12368 KB |
Output is correct |
11 |
Correct |
43 ms |
12356 KB |
Output is correct |
12 |
Correct |
42 ms |
12372 KB |
Output is correct |
13 |
Correct |
44 ms |
12368 KB |
Output is correct |
14 |
Correct |
452 ms |
88900 KB |
Output is correct |
15 |
Correct |
45 ms |
12368 KB |
Output is correct |
16 |
Correct |
389 ms |
89076 KB |
Output is correct |
17 |
Correct |
418 ms |
88912 KB |
Output is correct |
18 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
1116 KB |
Output is correct |
3 |
Correct |
4 ms |
1112 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 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 |
4 ms |
1244 KB |
Output is correct |
17 |
Correct |
44 ms |
8788 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |