#include <bits/stdc++.h>
using namespace std;
int n;
long long a, b, mod;
long long l, r, last=0, sum = 0;
vector<pair<long long, bool>> vec;
int ctr = 0;
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> a >> b; a /= __gcd(a, b);
if(a >= 4e18/b) mod = 4e18;
else mod = a*b;
while(n--) {
cin >> l >> r;
if(r-l+1 >= mod) {
cout << mod;
return 0;
}
l %= mod; r %= mod;
if(l <= r) vec.emplace_back(l, 0), vec.emplace_back(r+1, 1);
else vec.emplace_back(l, 0), vec.emplace_back(mod, 1), vec.emplace_back(0, 0), vec.emplace_back(r+1, 1);
}
sort(vec.begin(), vec.end());
for(auto e:vec) {
sum += min(ctr, 1) * (e.first-last);
if(e.second) ctr--;
else ctr++;
last = e.first;
}
cout << sum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
6 ms |
1312 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
398 ms |
35252 KB |
Output is correct |
3 |
Incorrect |
377 ms |
36940 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
398 ms |
35252 KB |
Output is correct |
3 |
Incorrect |
377 ms |
36940 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
398 ms |
35252 KB |
Output is correct |
3 |
Incorrect |
377 ms |
36940 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
47 ms |
7292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
6 ms |
1312 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |