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 __int128 asdf;
typedef pair<asdf, asdf> p;
ll _n, _a, _b;
asdf n, a, b, c, sz;
void print(__int128 x){
string s;
while(x){
s += (char)(x%10 + '0'); x /= 10;
}
reverse(s.begin(), s.end());
cout << s;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> _n >> _a >> _b;
n = _n, a = _a, b = _b;
sz = a / __gcd(a, b+1) * b;
vector<p> v;
for(int i=0; i<n; i++){
ll _l, _r; cin >> _l >> _r;
asdf l, r; l = _l, r = _r;
if(r-l+1 > sz){
print(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());
asdf ans = 0;
for(int i=0; i<v.size(); i++){
int j = i; asdf 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;
}
print(ans);
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<v.size(); i++){
~^~~~~~~~~
strange_device.cpp:41: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... |