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>
#define int long long
#define pii pair<int, int>
using namespace std;
const int MAX=1e18;
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
assert(0);
int n, a, b; cin >> n >> a >> b;
priority_queue<pii, vector<pii>, greater<pii>> pq, to_ans;
while(n--) {
int l, r; cin >> l >> r;
pq.push({l, r});
}
int Mod;
if(a>(MAX+b-1)/b) Mod=1e18+1;
else Mod=a*b;
while(!pq.empty()) {
int l=pq.top().first, r=pq.top().second;
pq.pop();
while(!pq.empty() && pq.top().first<=r) r=max(r, pq.top().second), pq.pop();
if((l+Mod-1)/Mod*Mod+Mod-1<=r) {cout << Mod << '\n'; return 0;}
if((l+Mod-1)/Mod*Mod<=r && l%Mod) to_ans.push({l%Mod, Mod-1}), to_ans.push({0, r%Mod});
else to_ans.push({l%Mod, r%Mod});
}
int ans=0;
while(!to_ans.empty()) {
int l=to_ans.top().first, r=to_ans.top().second;
to_ans.pop();
while(!to_ans.empty() && to_ans.top().first<=r) r=max(r, to_ans.top().second), to_ans.pop();
ans+=r-l+1;
}
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... |