#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
int main() {
ll n, A, B;
cin >> n >> A >> B;
ll P = A / __gcd(A, B + 1) * B;
set<pair<ll, ll> > st;
for(int i=0; i<n; i++) {
ll L, R;
cin >> L >> R;
if(P <= 0) {
st.insert({ L, R });
continue;
}
ll a = L % P, b = R % P;
if(L == R) {
st.insert({ a, b });
} else if(a < b) {
st.insert({ a, b });
} else {
st.insert({ a, P - 1 });
st.insert({ 0, b });
}
}
ll res = 0, right_point = -1;
for(auto &it : st) {
// cout << it.first << " " << it.second << '\n';
if(it.second <= right_point) continue;
if(it.first > right_point) {
res += it.second - it.first + 1;
right_point = it.second;
} else {
res += it.second - right_point;
}
}
cout << res << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
9 ms |
920 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
975 ms |
63036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
975 ms |
63036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
975 ms |
63036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
96 ms |
6448 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
9 ms |
920 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |