#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
vector <pair <ll, ll>> vec;
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout<<fixed;
int n;
cin >> n;
ll a, b;
cin >> a >> b;
a /= __gcd(a, b+1);
if(a <= 2000000000000000000LL/b) a *= b;
cout << a << endl;
while(n--){
ll l, r;
cin >> l >> r;
if(r-l+1 >= a){
cout << a << "\n";
return 0;
}
l %= a;
r %= a;
if(l > r){
vec.push_back({0, 1});
vec.push_back({r+1, -1});
vec.push_back({l, 1});
vec.push_back({a, -1});
}
else{
vec.push_back({l, 1});
vec.push_back({r+1, -1});
}
}
sort(vec.begin(), vec.end());
n = vec.size();
ll res = 0;
ll tren = 0;
for(int i=0; i<n; i++){
ll val = vec[i].first;
//cout << vec[i].first << " " << vec[i].second << endl;
if(i > 0) val -= vec[i-1].first;
if(tren) res += val;
tren += vec[i].second;
//cout << res << endl;
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |