#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, a, b;
cin >> n >> a >> b;
if (b >= 3e18 / a) {
int ans = 0;
while (n--) {
int l, r;
cin >> l >> r;
ans += r - l + 1;
}
cout << ans << endl;
return;
}
priority_queue<pair<int, bool>, vector<pair<int, bool> >, greater<pair<int, bool> > > pq;
int mod = a * b;
while (n--) {
int l, r;
cin >> l >> r;
l %= mod; r %= mod;
if (l > r) swap(l, r);
pq.push({l, true});
pq.push({r + 1, false});
}
int prev = 0, ans = 0;
int cnt = 0;
while (!pq.empty()) {
pair<int, bool> cur = pq.top();
pq.pop();
if (cnt) ans += cur.first - prev;
prev = cur.first;
cnt += (cur.second ? 1 : -1);
}
cout << ans << endl;
}
signed main() {
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
15 ms |
1320 KB |
Output is correct |
3 |
Incorrect |
16 ms |
1208 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
2 ms |
312 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1494 ms |
68720 KB |
Output is correct |
3 |
Incorrect |
1437 ms |
68880 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1494 ms |
68720 KB |
Output is correct |
3 |
Incorrect |
1437 ms |
68880 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1494 ms |
68720 KB |
Output is correct |
3 |
Incorrect |
1437 ms |
68880 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
152 ms |
7280 KB |
Output is correct |
3 |
Correct |
152 ms |
7244 KB |
Output is correct |
4 |
Correct |
1447 ms |
68924 KB |
Output is correct |
5 |
Correct |
144 ms |
7196 KB |
Output is correct |
6 |
Correct |
145 ms |
7196 KB |
Output is correct |
7 |
Correct |
145 ms |
7200 KB |
Output is correct |
8 |
Correct |
151 ms |
7276 KB |
Output is correct |
9 |
Correct |
147 ms |
7216 KB |
Output is correct |
10 |
Correct |
142 ms |
7224 KB |
Output is correct |
11 |
Correct |
146 ms |
7184 KB |
Output is correct |
12 |
Incorrect |
146 ms |
7308 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
15 ms |
1320 KB |
Output is correct |
3 |
Incorrect |
16 ms |
1208 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |