이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 4e18;
ll mul(ll a, ll b) {
if (a > (inf / b)) {
return inf;
} else {
return a * b;
}
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
ll A, B;
cin >> A >> B;
A /= __gcd(A, B + 1);
ll C = mul(A, B);
vector<pair<ll, int>> go;
for (int i = 0; i < n; ++i) {
ll l, r;
cin >> l >> r;
if (r - l + 1 >= C) {
go.emplace_back(0, 1);
go.emplace_back(C, -1);
} else if (l % C <= r % C) {
l %= C, r %= C;
go.emplace_back(l, 1);
go.emplace_back(r + 1, -1);
} else {
l %= C, r %= C;
go.emplace_back(l, 1);
go.emplace_back(C, -1);
go.emplace_back(0, 1);
go.emplace_back(r + 1, -1);
}
}
sort(go.begin(), go.end());
ll ans = 0;
int l = 0;
int cnt = 0;
while (l < go.size()) {
int r = l;
while (r < go.size() && go[r].first == go[l].first) {
cnt += go[r++].second;
}
if (cnt) {
ans += go[r].first - go[l].first;
}
l = r;
}
cout << ans << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'int main()':
strange_device.cpp:47:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (l < go.size()) {
~~^~~~~~~~~~~
strange_device.cpp:49:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (r < go.size() && go[r].first == go[l].first) {
~~^~~~~~~~~~~
# | 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... |