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;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
const ll MAX = 1e18;
vector<pll> vec;
// {Left, Right}
ll n, a, b, length, ans = 0;
void opr(ll l, ll r) {
ll pushl = min(l, r);
ll pushr = max(l, r);
if (pushl == 0) {
// pushl = length;
}
if (pushr == 0) {
// pushr = length;
}
vec.push_back({pushl, pushr});
}
void answer() {
sort(vec.begin(), vec.end());
ll idx = -1;
for (int i = 0; i < vec.size(); ++i)
{
// cout << vec[i].first << " " << vec[i].second << "\n";
pll now = vec[i];
if (now.second < now.first)
{
continue ;
}
if (idx >= now.first)
{
if (now.second <= idx)
{
continue ;
} else {
idx++;
ans += now.second - idx + 1;
idx = now.second;
}
} else {
idx = now.first;
ans += now.second - idx + 1;
idx = now.second;
}
}
cout << ans << "\n";
}
ll fpb(ll a, ll b) {
if (a == 0)
{
return b;
}
return fpb(b%a, a);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> a >> b;
ull lebek;
// if (a == 1) {
// lebek = b;
// } else {
// if (a % 2)
// {
// lebek = a * b;
// } else {
// lebek = (a/2) * b;
// }
// }
lebek = a / fpb(a, b+1) * b;
// length = lebek;
length = min(lebek, (ull)MAX);
for (int i = 0; i < n; ++i)
{
ll nowl, nowr;
cin >> nowl >> nowr;
if (nowr-nowl+1 >= length)
{
cout << length << "\n";
return 0;
}
if (nowl/length != nowr/length) {
opr(nowl % length + 1, length);
opr(1, nowr % length + 1);
} else {
opr(nowl % length + 1, nowr % length + 1);
}
}
answer();
return 0;
}
Compilation message (stderr)
strange_device.cpp: In function 'void answer()':
strange_device.cpp:31:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; 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... |