#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
cin.tie(0) -> ios_base::sync_with_stdio(0);
ll n, a, b;
cin >> n >> a >> b;
ll g;
if(a > 1e18 / b)
{
g = 1e18 + 2;
}
else
{
g = a * b / gcd(a, b + 1);
}
map<ll, vector<ll>> M;
for(int i = 0; i < n; i++)
{
ll l, r;
cin >> l >> r;
l %= g, r %= g;
if(r < l)
{
M[0].push_back(r);
M[l].push_back(g - 1);
}
else
{
M[l].push_back(r);
}
}
multiset<ll> S;
vector<pair<ll,ll>> intervals;
ll begin = 2e18, last = 0;
for(auto &[st, v] : M)
{
while(!S.empty() && *S.begin() < st)
{
S.erase(S.begin());
}
if(S.empty() && begin != 2e18)
{
intervals.push_back({begin, last});
begin = 2e18;
last = 0;
}
begin = min(begin, st);
for(auto i : v)
{
S.insert(i);
last = max(last, i);
}
}
if(!S.empty() && begin != 2e18)
{
cout << last << '\n';
while(!S.empty())
{
last = max(last, *S.begin());
S.erase(S.begin());
}
intervals.push_back({begin, last});
}
long long ans = 0;
for(auto [l, r] : intervals)
{
ans += r - l + 1;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
260 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 |
- |
# |
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 |
212 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 |
- |
# |
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 |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |