/* 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 = 2e18;
const int N = 1e6 + 50;
ll n, A, B;
pii 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].F += P[i].F/B;
P[i].S += P[i].S/B +1;
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+1)-(x.F+1)/C)-((pt+1)-(pt+1)/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 |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |