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>
typedef long long ll;
typedef long double ld;
using namespace std;
int n;
ll mod, a, b;
void calculate_mod()
{
if (((ld)a) * ((ld)b) > 2e18) mod = 2e18;
else mod = a*b;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> b;
calculate_mod();
vector<pair<ll, int> > v;
for (int i = 0; i < n; i++)
{
ll l, r;
cin >> l >> r;
if (r - l + 1 >= mod)
{
v.push_back({0, 1});
v.push_back({mod, -1});
}
else
{
l %= mod, r %= mod;
if (l <= r)
{
v.push_back({l, 1}), v.push_back({r+1, -1});
}
else
{
v.push_back({0, 1}), v.push_back({r+1, -1});
v.push_back({l, 1}), v.push_back({mod, -1});
}
}
}
//cout << "===========\n" << mod << "\n";
sort(v.begin(), v.end());
ll ans = 0; int sum = 0;
for (int i = 0; i < v.size() - 1; i++)
{
//cout << v[i].first << " " << v[i].second << "\n";
sum += v[i].second;
if (sum) ans += v[i+1].first-v[i].first;
}
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i = 0; i < v.size() - 1; 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... |