# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
677193 | Iliya | Strange Device (APIO19_strange_device) | C++17 | 1094 ms | 63256 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 F first
#define S second
#define pb push_back
#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 10;
const ll INF = 1e18;
const int MOD = 1e9 + 7;
ll gcd(ll a, ll b) {
return !b ? a : gcd(b, a % b);
}
map<ll, ll> PS;
ll n, l, r, A, B, G, P, pos, ans, last;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
scanf("%lld%lld%lld", &n, &A, &B);
G = gcd(A, B + 1);
P = (INF / B < A / G ? INF : A / G * B);
for(int i = 0; i < n; i++) {
scanf("%lld%lld", &l, &r);
if(r - l + 1 >= P)
return !(printf("%lld", P));
l %= P, r %= P;
if(l <= r)
PS[l]++, PS[r + 1]--;
else
PS[0]++, PS[r + 1]--, PS[l]++, PS[P]--;
}
for(auto x : PS) {
if(pos) ans += x.F - last;
pos += x.S;
if(pos) last = x.F;
}
printf("%lld", ans);
return 0;
}
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... |