# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033109 | 2024-07-24T12:57:10 Z | borisAngelov | Long Mansion (JOI17_long_mansion) | C++17 | 188 ms | 18260 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 500005; int n, q; int a[maxn]; int l[maxn]; int r[maxn]; vector<int> keysPos[maxn]; bool isPossible(int leftPos, int rightPos, int key) { if (keysPos[key].empty()) return false; int pos = lower_bound(keysPos[key].begin(), keysPos[key].end(), leftPos) - keysPos[key].begin(); return pos < keysPos[key].size() && keysPos[key][pos] <= rightPos; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n; for (int i = 1; i <= n - 1; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { int cnt; cin >> cnt; for (int j = 1; j <= cnt; ++j) { int key; cin >> key; keysPos[key].push_back(i); } } for (int i = 1; i <= n; ++i) { l[i] = r[i] = i; cout << "on " << i << endl; while (true) { //cout << "left " << isPossible(l[i], r[i], a[l[i] - 1]) << "\n"; if (l[i] > 1 && isPossible(l[i], r[i], a[l[i] - 1]) == true) { r[i] = max(r[i], r[l[i] - 1]); l[i] = l[l[i] - 1]; } else if (r[i] < n && isPossible(l[i], r[i], a[r[i]]) == true) { ++r[i]; } else { break; } } //cout << i << " -> " << l[i] << " " << r[i] << endl; } cin >> q; for (int i = 1; i <= q; ++i) { int x, y; cin >> x >> y; if (l[x] <= y && y <= r[x]) { cout << "YES\n"; } else { cout << "NO\n"; } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 12124 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 12124 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 188 ms | 18260 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 12124 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |