#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
ll A, B;
cin >> n >> A >> B;
int L = (A & 1 ? A : A >> 1);
map<ll, int> m;
while (n--) {
ll l, r;
cin >> l >> r;
if (L <= r - l + 1) {
m[0]++; m[L]--;
continue;
}
m[l % L]++; m[r % L + 1]--;
if (l % L > r % L) {
m[0]++; m[L]--;
}
}
vector<pair<ll, int>> v;
for (auto i : m) v.push_back(i);
int sm = 0;
ll ans = 0;
for (int i = 0; i + 1 < (int)v.size(); i++) {
sm += v[i].second;
ans += !!sm * (v[i + 1].first - v[i].first);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
456 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
525 ms |
98140 KB |
Output is correct |
3 |
Incorrect |
407 ms |
98128 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
525 ms |
98140 KB |
Output is correct |
3 |
Incorrect |
407 ms |
98128 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
525 ms |
98140 KB |
Output is correct |
3 |
Incorrect |
407 ms |
98128 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
34 ms |
3020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |