# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
126587 | roseanne_pcy | Strange Device (APIO19_strange_device) | C++14 | 911 ms | 49196 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>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
const int maxn = 1e6+5;
ll L[maxn], R[maxn];
vector< pair<ll, int> > sw;
int main()
{
int n;
ll A, B;
scanf("%d %lld %lld", &n, &A, &B);
ll k = A/__gcd(A, B+1);
bool over = false;
if(k*B/B != k) over = true;
ll len = 0;
for(int i = 1; i<= n; i++)
{
scanf("%lld %lld", &L[i], &R[i]);
len += (R[i]-L[i]+1);
}
if(over)
{
printf("%lld\n", len);
return 0;
}
for(int i = 1; i<= n; i++)
{
ll tmp = R[i]-L[i]+1;
if(tmp>= k*B)
{
printf("%lld\n", k*B);
return 0;
}
ll m1 = L[i]%(k*B);
ll m2 = R[i]%(k*B);
if(m1<= m2)
{
sw.pb({m1, 1});
sw.pb({m2+1, -1});
}
else
{
sw.pb({m1, 1});
sw.pb({k*B, -1});
sw.pb({0, 1});
sw.pb({m2+1, -1});
}
}
sort(sw.begin(), sw.end());
ll ans = 0;
int run = 0;
for(int i = 0; i+1< (int) sw.size(); i++)
{
run += sw[i].Y;
if(run> 0)
{
ans += sw[i+1].X-sw[i].X;
}
}
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... |