이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 10;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
long long A, B; cin >> A >> B;
if ((__int128_t)1 * A * B / __gcd(A, B + 1) >= INF){
long long ans = 0;
for (int i = 0; i < n; i++){
long long l, r; cin >> l >> r;
ans += r - l + 1;
}
cout << ans << '\n';
return 0;
}
long long D = (__int128_t)1 * A * B / __gcd(A, B + 1);
vector<pair<long long, int>> res;
for (int i = 0; i < n; i++){
long long l, r; cin >> l >> r;
r++;
if (r - l >= D){
cout << D << '\n';
return 0;
}
long long ll = D * (l / D + 1), rr = D * (r / D);
if (ll > rr){
res.emplace_back(l % D, 1);
res.emplace_back(r % D, -1);
}else{
res.emplace_back(l % D, 1);
res.emplace_back(D, -1);
res.emplace_back(0, 1);
res.emplace_back(r % D, -1);
}
}
sort(res.begin(), res.end());
// cerr << D << '\n';
// cerr << res.size() << '\n';
// for (auto &[t, d]: res)
// cerr << t << ' ' << d << endl;
int N = res.size(), cur = 0;
long long ans = 0;
for (int i = 0; i < N; ){
int r = i;
while (r < N && res[i].first == res[r].first) r++;
for (int j = i; j < r; j++)
cur += res[j].second;
if (cur > 0)
ans += res[r].first - res[i].first;
i = r;
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |