# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
392246 | BartolM | Strange Device (APIO19_strange_device) | C++17 | 605 ms | 53508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const ll MAX=1e18+2;
int n, fl=0;
ll A, B, gc;
vector <pll> v;
int main() {
scanf("%d %lld %lld", &n, &A, &B);
gc=__gcd(A, B+1);
ll block=A/gc*B;
if (A/gc>MAX/B) block=MAX;
for (int i=0; i<n; ++i) {
ll l, r;
scanf("%lld %lld", &l, &r);
if (r-l+1>block) fl=1;
l%=block; r%=block;
if (l<=r) v.pb(mp(l, r));
else v.pb(mp(l, block-1)), v.pb(mp(0, r));
}
if (fl) {
printf("%lld\n", block);
return 0;
}
sort(v.begin(), v.end());
ll lef=-1, rig=-2, sol=0;
for (pll pp:v) {
if (rig<pp.X) sol+=rig-lef+1, rig=pp.Y, lef=pp.X;
else rig=max(rig, pp.Y);
}
sol+=rig-lef+1;
printf("%lld\n", sol);
return 0;
}
Compilation message (stderr)
# | 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... |