| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1301017 | tamir1 | Obstacles for a Llama (IOI25_obstacles) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<int> T, H;
int N, M;
vector<int> max_reach; // max row reachable from row 0 in each column
void initialize(vector<int> _T, vector<int> _H) {
T = _T;
H = _H;
N = T.size();
M = H.size();
// For each column, find the highest row that is free
max_reach.assign(M, -1);
for (int j = 0; j < M; j++) {
int r = -1;
for (int i = 0; i < N; i++) {
if (T[i] > H[j]) r = i;
}
max_reach[j] = r;
}
// Make max_reach prefix maximum for fast queries
for (int j = 1; j < M; j++) {
max_reach[j] = max(max_reach[j], max_reach[j-1]);
}
}
bool can_reach(int L, int R, int S, int D) {
if (S > D) swap(S, D); // always go left-to-right
int highest_row = (L == 0 ? max_reach[D] : max_reach[D] - max_reach[L-1]);
// Check if there's a connected path from row 0 through columns L..R
// If highest_row >= 0, path exists
return (highest_row >= 0);
}
// For local testing
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> N >> M;
vector<int> t(N), h(M);
for (int i = 0; i < N; i++) cin >> t[i];
for (int j = 0; j < M; j++) cin >> h[j];
initialize(t, h);
cin >> Q;
while (Q--) {
int L, R, S, D;
cin >> L >> R >> S >> D;
cout << can_reach(L, R, S, D) << "\n";
}
}
