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;
typedef long long ll;
typedef pair<ll, ll> p;
ll n, a, b, c, sz;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> a >> b;
sz = a / __gcd(a, b+1) * b;
vector<p> v;
for(int i=0; i<n; i++){
ll l, r; cin >> l >> r;
if(r-l+1 > sz){
cout << sz; return 0;
}
l %= sz, r %= sz;
if(l <= r) v.emplace_back(l, r);
else v.emplace_back(l, sz-1), v.emplace_back(0, r);
}
sort(v.begin(), v.end());
ll ans = 0;
for(int i=0; i<v.size(); i++){
int j = i; ll now = v[i].second;
while(j < v.size() && v[j].first <= now){
now = max(now, v[j].second); j++;
}
ans += now - v[i].first + 1;
i = j - 1;
}
cout << ans;
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<v.size(); i++){
~^~~~~~~~~
strange_device.cpp:28:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j < v.size() && v[j].first <= now){
~~^~~~~~~~~~
# | 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... |