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;
#define ar array
#define int long long
/*
3 5 12
0 23
60 60
81 83
*/
const long long inf = 1e18 + 5;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, A, B; cin>>n>>A>>B;
int cyc = A / __gcd(A, B + 1);
if(cyc > inf / B) cyc = inf;
else cyc *= B;
vector<ar<int, 2>> tt;
for(int i=0;i<n;i++){
int l, r; cin>>l>>r;
if(r - l + 1 >= cyc){
cout<<cyc<<"\n";
return 0;
}
l %= cyc, r %= cyc;
if(l <= r){
tt.push_back({l, r});
} else {
tt.push_back({l, cyc - 1});
tt.push_back({0, r});
}
}
sort(tt.begin(), tt.end());
int res = 0, r = -1;
for(auto x : tt){
if(r < x[0]){
res += (x[1] - x[0] + 1);
} else if(r < x[1]){
res += (x[1] - r);
} r = max(r, x[1]);
}
cout<<res<<"\n";
}
# | 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... |