This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* In the name of God, aka Allah */
// let this be mytemp.cpp
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = (1ll<<60);
const int N = 1e6 + 50;
ll n, A, B;
pll P[N];
map<ll, ll> mp;
void solve() {
cin >> n >> A >> B;
ll C = B+1;
ll lcm = A*min((inf+A-1)/A, C/__gcd(A, C));
for (int i = 1; i <= n; i++) {
cin >> P[i].F >> P[i].S;
P[i].S ++;
P[i].F += P[i].F/B;
P[i].S += P[i].S/B;
if (P[i].S - P[i].F >= lcm) {
return cout << lcm - lcm/C << endl, void();
}
ll l = P[i].F % lcm, r = P[i].S % lcm;
mp[l]++;
mp[r]--;
if (r < l) mp[0]++, mp[lcm]--;
}
ll ans = 0;
ll bl = 0;
ll pt = 0;
for (pll x:mp) {
if (!bl) pt = x.F;
bl += x.S;
if (!bl) {
ans += (x.F-x.F/C)-(pt-pt/C);
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
solve();
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... |