# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
468449 | Killer2501 | Strange Device (APIO19_strange_device) | C++14 | 618 ms | 92432 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 ll long long
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e18+7;
const ll N = 1e6+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, c[N], a[N], b[N], h[N];
vector<pll> adj[N], kq;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void sol()
{
ll A, B;
cin >> n >> A >> B;
A /= __gcd(A, B+1);
if(A > mod / B)tong = mod;
else tong = A * B;
for(int i = 0; i < n; i ++)
{
cin >> a[i] >> b[i];
if(b[i]-a[i]+1 >= tong)
{
cout << tong;
return;
}
a[i] %= tong;
b[i] %= tong;
if(a[i] <= b[i])kq.pb({a[i], b[i]});
else
{
kq.pb({0, b[i]});
kq.pb({a[i], tong-1});
}
}
sort(kq.begin(), kq.end());
ll l = kq[0].fi, r = kq[0].se;
ans = r-l+1;
for(int i = 1; i < kq.size(); i ++)
{
if(kq[i].fi > r)
{
ans += kq[i].se - kq[i].fi + 1;
l = kq[i].fi;
r = kq[i].se;
}
else
{
ans += max(0ll, kq[i].se-r);
r = max(kq[i].se, r);
}
}
cout << ans;
}
int main()
{
if(fopen(task".in", "r"))
{
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
5 1
0 1 2
0 2 3
1 3 5
2 4 6
1 1
4 3
*/
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... |