# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
741456 | abczz | Strange Device (APIO19_strange_device) | C++14 | 0 ms | 0 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 <iostream>
#include <vector>
#include <array>
#define ll long long
using namespace std;
ll n, a, b, x, y, l, r, f;
vector<array<ll, 2>> A;
int main() {
cin >> n >> a >> b;
for (int i=0; i<n; ++i) {
cin >> x >> y;
l = y-x;
x %= (a*b);
if (x+l >= a*b) {
l -= a*b-x;
l = min(l, a*b-1);
A.push_back({x, a*b-1});
A.push_back({0, l});
}
else A.push_back({x, x+l});
}
sort(A.begin(), A.end());
l = r = -1e9;
++l;
for (auto [u, v] : A) {
if (r+1 < u) {
//cout << l << " " << r << endl;
f += r-l+1;
l = u, r = v;
}
else r = max(r, v);
}
//cout << l << " " << r << endl;
f += (r-l)+1;
cout << f << '\n';
}