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;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
ll gcd(ll a, ll b){ return b ? gcd(b,a%b) : a; }
int main() {
ll n, a, b; cin >> n >> a >> b;
a/=gcd(a, b+1);
__int128_t ml = a*b;
map<ll, ll> mp;
while(n--){
ll l, r; cin >> l >> r;
if(r-l+1>=ml){
cout << (ll)ml << endl;
return 0;
}
l%=ml;
r%=ml;
if(l>r){
mp[l]++;
mp[ml]--;
mp[0]++;
mp[r+1]--;
}
else{
mp[l]++;
mp[r+1]--;
}
}
// 1 0 1 -1 -1 0 1 0 -1
// 1 1 2 1 0 0 1 1 0
ll cnt=0, nw=0, ans=0, pcnt=0;
for(auto& u : mp){
cnt+=u.S;
// cout << "[" << u.first << ',' << u.second << ']' << cnt << endl;
if(!pcnt) nw=u.F;
if(!cnt) ans+=u.F-nw;
pcnt=cnt;
}
cout << ans;
}
# | 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... |