This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct interv{
long long l, r;
bool operator < (const interv &aux)const{
if(l != aux.l) return l < aux.l;
return r < aux.r;
}
};
interv a[2000005];
int n;
long long A, B;
int main()
{
cin >> n >> A >> B;
double lg1 = log2((double)A), lg2 = log2((double)B);
long long prod = 0;
if(lg1 + lg2 <= 63) prod = 1LL * A * B;
int m = n;
for(int i = 1; i <= n ; ++i){
cin >> a[i].l >> a[i].r;
if(prod != 0){
if(a[i].r - a[i].l + 1 >= prod){
a[i].l = 0; a[i].r = prod - 1;
continue ;
}
a[i].l %= prod, a[i].r %= prod;
if(a[i].r < a[i].l) a[++m].l = 0, a[m].r = a[i].r, a[i].r = prod - 1;
}
}
n = m;
sort(a + 1, a + n + 1);
long long Sol = 0, l = -2, r = -3;
for(int i = 1; i <= n ; ++i){
if(r < a[i].l){
Sol = Sol + (r - l + 1);
l = a[i].l; r = a[i].r;
}
else r = max(r, a[i].r);
}
Sol = Sol + (r - l + 1);
cout << Sol;
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... |