#include <bits/stdc++.h>
#define ll long long
#define name "Long Mansion"
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; ++i)
#define fid(i, a, b) for(int i = a; i >= b; --i)
#define maxn (int) (5e5 + 7)
using namespace std;
/// ma
int n;
vector<int> P[maxn];
int a[maxn], fl[maxn], fr[maxn];
int check(int l, int r, int x) {
auto it = lower_bound(all(P[x]), l);
return it != P[x].end() && (*it <= r);
}
void solve() {
cin >> n;
fi(i, 1, n - 1) cin >> a[i];
fi(i, 1, n) {
int sz, x; cin >> sz;
while(sz--) cin >> x, P[x].push_back(i);
}
fi(i, 1, n) {
int l = i, r = i, ok = 1;
while(ok) {
ok = 0;
if(l > 1 && check(l, r, a[l - 1])) {
ok = 1;
l = fl[l - 1], r = max(r, fr[l]);
}
else if(r < n && check(l, r, a[r])) { ++r, ok = 1; }
}
fl[i] = l, fr[i] = r;
}
int q; cin >> q;
fi(i, 1, q) {
int x, y; cin >> x >> y;
if(fl[x] <= y && y <= fr[x]) cout << "YES\n";
else cout << "NO\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
if(fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
solve();
}
Compilation message
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen(name".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen(name".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12372 KB |
Output is correct |
2 |
Correct |
24 ms |
12356 KB |
Output is correct |
3 |
Correct |
101 ms |
12372 KB |
Output is correct |
4 |
Correct |
12 ms |
12372 KB |
Output is correct |
5 |
Correct |
11 ms |
12116 KB |
Output is correct |
6 |
Correct |
13 ms |
12372 KB |
Output is correct |
7 |
Correct |
14 ms |
12232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12372 KB |
Output is correct |
2 |
Correct |
24 ms |
12356 KB |
Output is correct |
3 |
Correct |
101 ms |
12372 KB |
Output is correct |
4 |
Correct |
12 ms |
12372 KB |
Output is correct |
5 |
Correct |
11 ms |
12116 KB |
Output is correct |
6 |
Correct |
13 ms |
12372 KB |
Output is correct |
7 |
Correct |
14 ms |
12232 KB |
Output is correct |
8 |
Correct |
76 ms |
17996 KB |
Output is correct |
9 |
Correct |
75 ms |
17984 KB |
Output is correct |
10 |
Correct |
108 ms |
18524 KB |
Output is correct |
11 |
Correct |
190 ms |
18816 KB |
Output is correct |
12 |
Correct |
69 ms |
17604 KB |
Output is correct |
13 |
Correct |
65 ms |
18156 KB |
Output is correct |
14 |
Correct |
73 ms |
18404 KB |
Output is correct |
15 |
Correct |
90 ms |
18160 KB |
Output is correct |
16 |
Correct |
67 ms |
17996 KB |
Output is correct |
17 |
Correct |
65 ms |
18252 KB |
Output is correct |
18 |
Correct |
68 ms |
18220 KB |
Output is correct |
19 |
Correct |
71 ms |
18260 KB |
Output is correct |
20 |
Correct |
82 ms |
18300 KB |
Output is correct |
21 |
Correct |
72 ms |
17740 KB |
Output is correct |
22 |
Correct |
63 ms |
18252 KB |
Output is correct |
23 |
Correct |
92 ms |
18148 KB |
Output is correct |
24 |
Correct |
82 ms |
18000 KB |
Output is correct |
25 |
Correct |
66 ms |
17996 KB |
Output is correct |
26 |
Correct |
90 ms |
17996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3037 ms |
16896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12372 KB |
Output is correct |
2 |
Correct |
24 ms |
12356 KB |
Output is correct |
3 |
Correct |
101 ms |
12372 KB |
Output is correct |
4 |
Correct |
12 ms |
12372 KB |
Output is correct |
5 |
Correct |
11 ms |
12116 KB |
Output is correct |
6 |
Correct |
13 ms |
12372 KB |
Output is correct |
7 |
Correct |
14 ms |
12232 KB |
Output is correct |
8 |
Correct |
76 ms |
17996 KB |
Output is correct |
9 |
Correct |
75 ms |
17984 KB |
Output is correct |
10 |
Correct |
108 ms |
18524 KB |
Output is correct |
11 |
Correct |
190 ms |
18816 KB |
Output is correct |
12 |
Correct |
69 ms |
17604 KB |
Output is correct |
13 |
Correct |
65 ms |
18156 KB |
Output is correct |
14 |
Correct |
73 ms |
18404 KB |
Output is correct |
15 |
Correct |
90 ms |
18160 KB |
Output is correct |
16 |
Correct |
67 ms |
17996 KB |
Output is correct |
17 |
Correct |
65 ms |
18252 KB |
Output is correct |
18 |
Correct |
68 ms |
18220 KB |
Output is correct |
19 |
Correct |
71 ms |
18260 KB |
Output is correct |
20 |
Correct |
82 ms |
18300 KB |
Output is correct |
21 |
Correct |
72 ms |
17740 KB |
Output is correct |
22 |
Correct |
63 ms |
18252 KB |
Output is correct |
23 |
Correct |
92 ms |
18148 KB |
Output is correct |
24 |
Correct |
82 ms |
18000 KB |
Output is correct |
25 |
Correct |
66 ms |
17996 KB |
Output is correct |
26 |
Correct |
90 ms |
17996 KB |
Output is correct |
27 |
Execution timed out |
3037 ms |
16896 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |