이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int M = 1e4+2;
struct rng {int l, r, i;};
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, q;
cin >> n >> q;
vector<rng> v(n);
for (auto &[l, r, i]:v) cin >> l >> r;
for (int i = 0; i < n; i++) v[i].i = i;
bitset<100005> vis;
while (q--) {
int a, b;
cin >> a >> b; a--; b--;
if (a == b) {
cout << 0 << endl;
continue;
}
vis[b] = 1;
int ans = 0;
rng cr = v[b];
while (true) {
// cout << q << "I: "<< cr.i+1 << endl;
rng tmp;
bool ch = 0;
int mn = INT_MAX;
for (auto [l, r, i]:v) {
if (!vis[i]) {
if (cr.l <= r && r <= cr.r) {
if (i == a) {
ans++; ch = 0;
break;
}
if (l < mn) {
ch = true;
tmp = {l, r, i};
mn = l;
}
}
}
}
if (!ch) break;
if (tmp.l < cr.l) cr = tmp;
else break;
ans++;
vis[cr.i] = 1;
} vis = 0;
if (cr.l <= v[a].r && v[a].r <= cr.r) {
cout << ans << endl;
} else {
cout << "impossible" << endl;
}
}
return 0;
}
/*
8 5
1 2
3 4
1 5
6 7
5 10
10 20
15 20
999999999 1000000000
1 6
1 7
2 4
3 3
5 8
5 2
1 3
2 4
4 7
7 9
3 7
1 4
3 2
*/
컴파일 시 표준 에러 (stderr) 메시지
events.cpp: In function 'int main()':
events.cpp:59:28: warning: 'tmp.rng::r' may be used uninitialized in this function [-Wmaybe-uninitialized]
59 | if (cr.l <= v[a].r && v[a].r <= cr.r) {
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
events.cpp:32:17: warning: 'tmp.rng::i' may be used uninitialized in this function [-Wmaybe-uninitialized]
32 | rng tmp;
| ^~~
events.cpp:53:13: warning: 'tmp.rng::l' may be used uninitialized in this function [-Wmaybe-uninitialized]
53 | if (tmp.l < cr.l) cr = tmp;
| ^~
# | 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... |