# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
348119 | arnold518 | Strange Device (APIO19_strange_device) | C++14 | 867 ms | 82936 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.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e6;
int N;
ll A, B, L;
pll P[MAXN+10];
map<ll, ll> M;
void addrange(ll l, ll r)
{
M[l]++;
M[r+1]--;
}
int main()
{
scanf("%d%lld%lld", &N, &A, &B);
for(int i=1; i<=N; i++) scanf("%lld%lld", &P[i].first, &P[i].second);
L=__gcd(A, B+1);
if(A/L>=(ll)1e18/B) L=1e18;
else L=A/L*B;
for(int i=1; i<=N; i++)
{
ll l=P[i].first, r=P[i].second;
if(r-l+1>=L) return !printf("%lld\n", L);
if(l%L<=r%L) addrange(l%L, r%L);
else
{
addrange(l%L, L-1);
addrange(0, r%L);
}
}
M[L];
ll t=0, ans=0;
for(auto it=M.begin(); it!=M.end(); it++)
{
if(it->first==L) break;
t+=it->second;
if(t) ans+=next(it)->first-it->first;
}
printf("%lld\n", ans);
}
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... |