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;
vector<pair<long long, long long> > vec;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, a, b, num, curl, curr, ans=0;
cin >> n >> a >> b;
if (log2(a)+log2(b)>=60.0)
num=2e18;
else
num=a*b/gcd(a*b, b+1);
for (long long i=1; i<=n; i++)
{
long long l, r;
cin >> l >> r;
if (l+num<=r)
vec.push_back({0, num-1});
else if (l%num<=r%num)
vec.push_back({l%num, r%num});
else
{
vec.push_back({l%num, num-1});
vec.push_back({0, r%num});
}
}
sort(vec.begin(), vec.end());
curl=vec[0].first;
curr=vec[0].second;
for (long long i=1; i<vec.size(); i++)
{
if (curr<vec[i].first)
{
ans+=curr-curl+1;
curl=vec[i].first;
}
curr=max(curr, vec[i].second);
}
cout << ans+curr-curl+1;
return 0;
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:32:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (long long i=1; i<vec.size(); i++)
| ~^~~~~~~~~~~
# | 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... |