# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
741461 | abczz | 이상한 기계 (APIO19_strange_device) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <array>
#define ll long long
using namespace std;
ll n, a, b;
bool B;
vector <ll> V;
__int128 z, x, y, l, r, f;
vector<array<__int128, 2>> A;
int main() {
cin >> n >> a >> b;
x = a;
y = b;
z = x*y;
for (int i=0; i<n; ++i) {
cin >> a >> b;
x = a, y = b;
l = y-x;
x %= z;
if (x+l >= z) {
l -= z;
l = min(l, z-1);
A.push_back({x, z-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) {
f += r-l+1;
l = u, r = v;
}
else r = max(r, v);
}
f += (r-l)+1;
while (f) {
V.push_back(f%10);
f /= 10;
}
reverse(V.begin(), V.end());
for (auto u : V) {
cout << u;
}
cout << '\n';
}