#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;
r = max(r, fr[l - 1]), l = fl[l - 1];
}
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12452 KB |
Output is correct |
2 |
Correct |
11 ms |
12332 KB |
Output is correct |
3 |
Correct |
10 ms |
12368 KB |
Output is correct |
4 |
Correct |
13 ms |
12376 KB |
Output is correct |
5 |
Correct |
11 ms |
12144 KB |
Output is correct |
6 |
Correct |
10 ms |
12368 KB |
Output is correct |
7 |
Correct |
11 ms |
12344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12452 KB |
Output is correct |
2 |
Correct |
11 ms |
12332 KB |
Output is correct |
3 |
Correct |
10 ms |
12368 KB |
Output is correct |
4 |
Correct |
13 ms |
12376 KB |
Output is correct |
5 |
Correct |
11 ms |
12144 KB |
Output is correct |
6 |
Correct |
10 ms |
12368 KB |
Output is correct |
7 |
Correct |
11 ms |
12344 KB |
Output is correct |
8 |
Correct |
78 ms |
17976 KB |
Output is correct |
9 |
Correct |
73 ms |
18100 KB |
Output is correct |
10 |
Correct |
72 ms |
18508 KB |
Output is correct |
11 |
Correct |
88 ms |
18764 KB |
Output is correct |
12 |
Correct |
81 ms |
17588 KB |
Output is correct |
13 |
Correct |
71 ms |
18260 KB |
Output is correct |
14 |
Correct |
76 ms |
18248 KB |
Output is correct |
15 |
Correct |
76 ms |
18240 KB |
Output is correct |
16 |
Correct |
67 ms |
18192 KB |
Output is correct |
17 |
Correct |
88 ms |
18192 KB |
Output is correct |
18 |
Correct |
69 ms |
18176 KB |
Output is correct |
19 |
Correct |
80 ms |
18248 KB |
Output is correct |
20 |
Correct |
66 ms |
18192 KB |
Output is correct |
21 |
Correct |
61 ms |
18100 KB |
Output is correct |
22 |
Correct |
63 ms |
18248 KB |
Output is correct |
23 |
Correct |
69 ms |
17992 KB |
Output is correct |
24 |
Correct |
67 ms |
17992 KB |
Output is correct |
25 |
Correct |
86 ms |
17972 KB |
Output is correct |
26 |
Correct |
69 ms |
17996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
24528 KB |
Output is correct |
2 |
Correct |
135 ms |
24140 KB |
Output is correct |
3 |
Correct |
128 ms |
23992 KB |
Output is correct |
4 |
Correct |
156 ms |
24404 KB |
Output is correct |
5 |
Correct |
130 ms |
24560 KB |
Output is correct |
6 |
Correct |
118 ms |
22848 KB |
Output is correct |
7 |
Correct |
104 ms |
22504 KB |
Output is correct |
8 |
Correct |
130 ms |
22604 KB |
Output is correct |
9 |
Correct |
99 ms |
22604 KB |
Output is correct |
10 |
Correct |
103 ms |
22604 KB |
Output is correct |
11 |
Correct |
101 ms |
22580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12452 KB |
Output is correct |
2 |
Correct |
11 ms |
12332 KB |
Output is correct |
3 |
Correct |
10 ms |
12368 KB |
Output is correct |
4 |
Correct |
13 ms |
12376 KB |
Output is correct |
5 |
Correct |
11 ms |
12144 KB |
Output is correct |
6 |
Correct |
10 ms |
12368 KB |
Output is correct |
7 |
Correct |
11 ms |
12344 KB |
Output is correct |
8 |
Correct |
78 ms |
17976 KB |
Output is correct |
9 |
Correct |
73 ms |
18100 KB |
Output is correct |
10 |
Correct |
72 ms |
18508 KB |
Output is correct |
11 |
Correct |
88 ms |
18764 KB |
Output is correct |
12 |
Correct |
81 ms |
17588 KB |
Output is correct |
13 |
Correct |
71 ms |
18260 KB |
Output is correct |
14 |
Correct |
76 ms |
18248 KB |
Output is correct |
15 |
Correct |
76 ms |
18240 KB |
Output is correct |
16 |
Correct |
67 ms |
18192 KB |
Output is correct |
17 |
Correct |
88 ms |
18192 KB |
Output is correct |
18 |
Correct |
69 ms |
18176 KB |
Output is correct |
19 |
Correct |
80 ms |
18248 KB |
Output is correct |
20 |
Correct |
66 ms |
18192 KB |
Output is correct |
21 |
Correct |
61 ms |
18100 KB |
Output is correct |
22 |
Correct |
63 ms |
18248 KB |
Output is correct |
23 |
Correct |
69 ms |
17992 KB |
Output is correct |
24 |
Correct |
67 ms |
17992 KB |
Output is correct |
25 |
Correct |
86 ms |
17972 KB |
Output is correct |
26 |
Correct |
69 ms |
17996 KB |
Output is correct |
27 |
Correct |
134 ms |
24528 KB |
Output is correct |
28 |
Correct |
135 ms |
24140 KB |
Output is correct |
29 |
Correct |
128 ms |
23992 KB |
Output is correct |
30 |
Correct |
156 ms |
24404 KB |
Output is correct |
31 |
Correct |
130 ms |
24560 KB |
Output is correct |
32 |
Correct |
118 ms |
22848 KB |
Output is correct |
33 |
Correct |
104 ms |
22504 KB |
Output is correct |
34 |
Correct |
130 ms |
22604 KB |
Output is correct |
35 |
Correct |
99 ms |
22604 KB |
Output is correct |
36 |
Correct |
103 ms |
22604 KB |
Output is correct |
37 |
Correct |
101 ms |
22580 KB |
Output is correct |
38 |
Correct |
194 ms |
33100 KB |
Output is correct |
39 |
Correct |
195 ms |
33880 KB |
Output is correct |
40 |
Correct |
174 ms |
30796 KB |
Output is correct |
41 |
Correct |
212 ms |
31416 KB |
Output is correct |
42 |
Correct |
143 ms |
24140 KB |
Output is correct |
43 |
Correct |
145 ms |
23884 KB |
Output is correct |
44 |
Correct |
183 ms |
29776 KB |
Output is correct |
45 |
Correct |
159 ms |
30032 KB |
Output is correct |
46 |
Correct |
195 ms |
30540 KB |
Output is correct |
47 |
Correct |
112 ms |
24396 KB |
Output is correct |
48 |
Correct |
135 ms |
23632 KB |
Output is correct |
49 |
Correct |
184 ms |
29260 KB |
Output is correct |
50 |
Correct |
188 ms |
29772 KB |
Output is correct |
51 |
Correct |
215 ms |
30964 KB |
Output is correct |
52 |
Correct |
134 ms |
31052 KB |
Output is correct |
53 |
Correct |
172 ms |
36992 KB |
Output is correct |
54 |
Correct |
195 ms |
43132 KB |
Output is correct |
55 |
Correct |
200 ms |
37104 KB |
Output is correct |