#include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0) -> ios_base::sync_with_stdio(0);
long long n, a, b;
cin >> n >> a >> b;
long long g = a * b / gcd(a, b + 1);
map<int, vector<int>> M;
for(int i = 0; i < n; i++)
{
int 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<int> S;
vector<pair<int,int>> intervals;
int begin = 1e9, last = 0;
for(auto &[st, v] : M)
{
while(!S.empty() && *S.begin() < st)
{
S.erase(S.begin());
}
if(S.empty() && begin != 1e9)
{
intervals.push_back({begin, last});
begin = 1e9;
last = 0;
}
begin = min(begin, st);
for(auto i : v)
{
S.insert(i);
last = max(last, i);
}
}
if(!S.empty() && begin != 1e9)
{
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 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Incorrect |
6 ms |
872 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
580 ms |
55100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
580 ms |
55100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
580 ms |
55100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
47 ms |
5852 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Incorrect |
6 ms |
872 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |