| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1309478 | thuhienne | Railway Trip 2 (JOI22_ho_t4) | C++20 | 2095 ms | 2860 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define thuhien ""
#define re exit(0);
const int maxm = 2e5 + 9;
const int maxn = 1e5 + 9;
int n,k,m;
pair <int,int> line[maxm];
int q;
int maxreach[maxn],minreach[maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
if (fopen(thuhien".inp","r")) {
freopen(thuhien".inp","r",stdin);
freopen(thuhien".out","w",stdout);
}
cin >> n >> k >> m;
for (int i = 1;i <= n;i++) maxreach[i] = minreach[i] = i;
for (int i = 1;i <= m;i++) {
cin >> line[i].first >> line[i].second;
if (line[i].first < line[i].second) {
for (int j = line[i].first;j <= min(line[i].first + k - 1,line[i].second - 1);j++) {
maxreach[j] = max(maxreach[j],line[i].second);
}
} else {
for (int j = line[i].first;j >= max(line[i].first - k + 1,line[i].second + 1);j--) {
minreach[j] = min(minreach[j],line[i].second);
}
}
}
int q;cin >> q;
while (q--) {
int s,t;cin >> s >> t;
int l = s,r = s,nextl,nextr,res = 0;
while (r < t || l > t) {
res++;
nextl = l,nextr = r;
for (int i = l;i <= r;i++) {
nextl = min(nextl,minreach[i]);
nextr = max(nextr,maxreach[i]);
}
if (l == nextl && r == nextr) {
res = 1e9;
break;
}
l = nextl,r = nextr;
}
cout << (res == 1e9 ? -1 : res) << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
