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;
int v[N];
int main(){
// freopen("file.txt", "r", stdin);
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
if(true){
// (2x % a, 0)
// 2x % a == 0
// if a is odd, then the ans is of length a (the 2 will never
// contribute)
// if a is even, then the ans of of length a/2
ll den = (a%2 == 0 ? a/2 : a);
if (b){
// w (B + 1) mod A = 0
if (b/gcd(a, b+1) >= (INF+1)/a)
den = INF+1;
else
den = a/gcd(a, b+1)*b;
}
vector<pair<ll, ll>> v;
map<ll, ll> mp;
while(n--){
ll l, r;
scanf("%lld%lld", &l ,&r);
ll _l = l%den, _r = r%den;
if (r-l+1 >= den){
printf("%lld\n", den);
return 0;
}
if(_l > _r)
v.pb({_l, den-1}), v.pb({0, _r});
else
v.pb({_l, _r});
}
for(auto &[l, r] : v)
mp[l] = max(mp[l], r);
ll r_ = 0, ans = 0;
for(auto &i : mp){
if(i.ss < r_)
continue;
r_ = max(r_, i.ff);
ans += i.ss-r_+1;
r_ = i.ss+1;
}
printf("%lld\n", ans);
return 0;
}
set<pair<ll, ll>> st;
while(n--){
ll l, r;
scanf("%lld%lld", &l, &r);
for(ll x = l; x <= r; ++x)
st.insert({(x+x/b)%a, x%b});
}
ll answer = st.size();
printf("%lld\n", answer);
return 0;
}
Compilation message (stderr)
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d%d%d", &n, &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%lld%lld", &l ,&r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%lld%lld", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
# | 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... |