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;
using ll = long long;
const int MAXN = 2e6+5;
map<ll, bool> visited;
vector< pair<ll, ll> > imp;
ll n, a, b;
int main()
{
cin >> n >> a >> b;
ll sum = 0;
ll big = 1;
if(2e18 / b < a)
big = 2e18;
else
big = a * b;
for(int i = 1; i <= n; i++)
{
ll f, s;
cin >> f >> s;
if(s - f >= big - 1)
{
imp.push_back({0, 1});
imp.push_back({big - 1, 2});
} else
{
if(f % big <= s % big)
{
imp.push_back({f % big, 1});
imp.push_back({s % big, 2});
} else
{
imp.push_back({0, 1});
imp.push_back({s % big, 2});
imp.push_back({f % big, 1});
imp.push_back({big - 1, 2});
}
}
}
// cout << seg[0].sum << "\n";
sort(imp.begin(), imp.end());
ll cnt = 0;
ll ans = 0;
ll last = -1;
for(pair<ll, ll> e : imp)
{
//cout << ans << " " << cnt << " " << last << "\n";
if(last != -1 && cnt > 0)
{
ans += e.first - last;
if(!visited[last])
{
ans++;
visited[last] = true;
}
visited[e.first] = true;
}
if(e.second == 1)
{
cnt++;
last = e.first;
} else
{
cnt--;
last = e.first;
}
}
cout << ans << "\n";
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:13:8: warning: unused variable 'sum' [-Wunused-variable]
13 | ll sum = 0;
| ^~~
# | 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... |