# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140648 | HellAngel | Bridges (APIO19_bridges) | C++14 | 16 ms | 2040 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>
#define int long long
const int inf = (int)1e18 + 69;
using namespace std;
const int maxn = 1e6 + 7;
int n, l[maxn], r[maxn], a, b, sum = 0, IT[4 * maxn];
vector<pair<int, int>> vt;
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
cin >> n >> a >> b;
for(int i = 1; i <= n; i++) cin >> l[i] >> r[i], sum += r[i] - l[i] + 1;
int Dist = a / __gcd(a, b + 1);
if(inf / Dist < b) return cout << sum, 0;
Dist *= b;
/// tối đa có dist giá trị
for(int i = 1; i <= n; i++)
{
int gau = l[i] % Dist;
int meo = r[i] % Dist;
if(r[i] - l[i] + 1 >= Dist) return cout << Dist << '\n', 0;
else
{
if(gau <= meo)
{
vt.push_back({gau, meo});
}
else
{
vt.push_back({gau, Dist - 1});
vt.push_back({0, meo});
}
}
}
sort(vt.begin(),vt.end());
assert(vt.size() != 0);
int ans1 = vt[0].second - vt[0].first + 1, curl1 = vt[0].second + 1;
for(int i = 1; i < vt.size(); i++)
{
if(vt[i].second >= curl1)
{
ans1 += vt[i].second - max(curl1, vt[i].first) + 1;
curl1 = vt[i].second + 1;
}
}
cout << ans1;
}
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... |