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;
int n;
long long a, b, mod;
long long l, r, last=0, sum = 0;
vector<pair<long long, bool>> vec;
int ctr = 0;
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> a >> b;
if(a >= 2e18/b) mod = 2e18;
else mod = a*b;
while(n--) {
cin >> l >> r;
if(r-l+1 >= mod) {
cout << mod;
return 0;
}
l %= mod; r %= mod;
if(l <= r) vec.emplace_back(l, 0), vec.emplace_back(r+1, 1);
else vec.emplace_back(l, 0), vec.emplace_back(mod, 1), vec.emplace_back(0, 0), vec.emplace_back(r+1, 1);
}
sort(vec.begin(), vec.end());
for(auto e:vec) {
sum += min(ctr, 1) * (e.first-last);
if(e.second) ctr--;
else ctr++;
last = e.first;
}
cout << sum;
}
# | 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... |