Submission #1266778

#TimeUsernameProblemLanguageResultExecution timeMemory
1266778nguynLong Mansion (JOI17_long_mansion)C++20
0 / 100
156 ms20728 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second #define pb push_back #define pii pair<int, int> const int N = 5e5 + 5; int n, q; vector<int> vec[N]; int c[N]; int l[N], r[N], nxt[N], prv[N]; int lst[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i < n; i++) cin >> c[i]; for (int i = 1; i <= n; i++) { int sz; cin >> sz; for (int j = 1; j <= sz; j++) { int x; cin >> x; vec[i].pb(x); } } for (int i = 1; i <= n; i++) { for (int j : vec[i]) lst[j] = i; if (i < n) prv[i] = lst[c[i]]; } for (int i = 1; i < n; i++) { cout << prv[i] << ' ' << nxt[i] << endl; } for (int i = 1; i <= n; i++) lst[i] = 0; for (int i = n; i >= 1; i--) { if (i < n) nxt[i] = lst[c[i]]; for (int j : vec[i]) lst[j] = i; } for (int i = 1; i <= n; i++) { l[i] = r[i] = i; while(1) { if (l[i] > 1 && nxt[l[i] - 1] <= r[i] && nxt[l[i] - 1]) { l[i]--; if (r[l[i]] >= i) { r[i] = r[l[i]]; l[i] = l[l[i]]; break; } } else if (r[i] < n && prv[r[i]] >= l[i] && prv[r[i]]) { r[i]++; } else { break; } } } 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"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...