# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1032702 | KasymK | Strange Device (APIO19_strange_device) | C++17 | 296 ms | 26976 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"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int MOD = 1e9+7;
const int N = 1e5+5;
const ll INF = 1e18+1;
int v[N];
int main(){
// freopen("file.txt", "r", stdin);
int n;
scanf("%d",&n);
ll a, b;
scanf("%lld%lld",&a,&b);
ll ad = a/__gcd(a, b+1);
if(ad <= INF/b)
ad *= b;
else
ad = INF;
vector<pii>v;
for(int i = 1; i <= n; ++i){
ll l, r;
scanf("%lld%lld", &l, &r);
if(r-l+1 >= ad){
printf("%lld\n", ad);
return 0;
}
l %= ad, r %= ad;
if(l <= r)
v.pb({l, r});
else
v.pb({l, ad-1}), v.pb({0, r});
}
sort(all(v));
pii as = {-1, -1};
ll ans = 0;
for(auto i : v){
if(as.ss < i.ff){
if(as.ff != -1)
ans += as.ss-as.ff+1;
as = i;
}
else
umax(as.ss, i.ss);
}
printf("%lld\n", ans+as.ss-as.ff+1);
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... |