# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1135883 | Thanhs | Strange Device (APIO19_strange_device) | C++20 | 300 ms | 17040 KiB |
#include <bits/stdc++.h>
using namespace std;
#define name "TENBAI"
#define fi first
#define se second
#define int long long
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int inf = 1e18 + 1;
vector<pair<int, int>> v;
int n, a, b, c, ans;
void solve()
{
cin >> n >> a >> b;
int g = __gcd(a, b + 1);
a /= g;
if (inf / a < b)
c = inf;
else
c = a * b;
while (n--)
{
int l, r;
cin >> l >> r;
if (l / c == r / c)
v.emplace_back(l % c, r % c);
else if (l / c == r / c - 1)
v.emplace_back(l % c, c - 1), v.emplace_back(0, r % c);
else
{
cout << c;
return;
}
}
sort(v.begin(), v.end());
// for (auto t : v)
// cout << t.fi << ' ' << t.se << endl;
int l = v[0].fi, r = v[0].se;
for (auto t : v)
{
if (t.fi > r)
{
ans += r - l + 1;
l = t.fi, r = t.se;
}
else
setmax(r, t.se);
}
ans += r - l + 1;
cout << ans;
}
signed main()
{
if (fopen("in.txt", "r"))
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
else if (fopen(name".inp", "r"))
{
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int tc = 1;
// cin >> tc;
while (tc--)
solve();
}
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... |