/*
ID: varunra2
LANG: C++
TASK: mansion
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif
#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second
const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions
int main() {
// #ifndef ONLINE_JUDGE
// freopen("mansion.in", "r", stdin);
// freopen("mansion.out", "w", stdout);
// #endif
cin.sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
VI b(n);
VI c(n);
VVI gps(n);
for (int i = 0; i < n - 1; i++) {
cin >> c[i];
c[i]--;
}
for (int i = 0; i < n; i++) {
cin >> b[i];
for (int j = 0; j < b[i]; j++) {
int u;
cin >> u;
u--;
gps[i].PB(u);
}
}
VI bef(n), aft(n);
VI lst(n, -1);
for (int i = 0; i < n - 1; i++) {
trav(x, gps[i]) { lst[x] = i; }
bef[i] = lst[c[i]];
}
lst.assign(n, n);
for (int i = n - 1; i >= 1; i--) {
trav(x, gps[i]) { lst[x] = i; }
aft[i - 1] = lst[c[i - 1]];
}
VI l(n), r(n);
for (int i = 0; i < n; i++) {
l[i] = i;
r[i] = i;
bool ok = true;
while (ok) {
ok = false;
if (l[i] and aft[l[i] - 1] <= r[i]) {
r[i] = max(r[i], r[l[i] - 1]);
l[i] = l[l[i] - 1];
ok = true;
}
if (r[i] < n - 1 and bef[r[i]] >= l[i]) {
r[i]++;
ok = true;
}
}
}
int q;
cin >> q;
debug(l);
debug(r);
while (q--) {
int x, y;
cin >> x >> y;
x--, y--;
if (y <= r[x] and y >= l[x]) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
Compilation message
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
long_mansion.cpp:124:3: note: in expansion of macro 'debug'
124 | debug(l);
| ^~~~~
long_mansion.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
long_mansion.cpp:125:3: note: in expansion of macro 'debug'
125 | debug(r);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
896 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
896 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
106 ms |
6520 KB |
Output is correct |
9 |
Correct |
109 ms |
6392 KB |
Output is correct |
10 |
Correct |
106 ms |
6776 KB |
Output is correct |
11 |
Correct |
106 ms |
7288 KB |
Output is correct |
12 |
Correct |
96 ms |
6008 KB |
Output is correct |
13 |
Correct |
103 ms |
6648 KB |
Output is correct |
14 |
Correct |
102 ms |
6648 KB |
Output is correct |
15 |
Correct |
101 ms |
6648 KB |
Output is correct |
16 |
Correct |
95 ms |
6460 KB |
Output is correct |
17 |
Correct |
102 ms |
6648 KB |
Output is correct |
18 |
Correct |
102 ms |
6648 KB |
Output is correct |
19 |
Correct |
101 ms |
6652 KB |
Output is correct |
20 |
Correct |
98 ms |
6648 KB |
Output is correct |
21 |
Correct |
96 ms |
6392 KB |
Output is correct |
22 |
Correct |
100 ms |
6520 KB |
Output is correct |
23 |
Correct |
104 ms |
6452 KB |
Output is correct |
24 |
Correct |
105 ms |
6392 KB |
Output is correct |
25 |
Correct |
103 ms |
6392 KB |
Output is correct |
26 |
Correct |
105 ms |
6392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
18160 KB |
Output is correct |
2 |
Correct |
212 ms |
18040 KB |
Output is correct |
3 |
Correct |
188 ms |
17736 KB |
Output is correct |
4 |
Correct |
193 ms |
18196 KB |
Output is correct |
5 |
Correct |
208 ms |
18168 KB |
Output is correct |
6 |
Correct |
156 ms |
16888 KB |
Output is correct |
7 |
Correct |
155 ms |
16760 KB |
Output is correct |
8 |
Correct |
160 ms |
16632 KB |
Output is correct |
9 |
Correct |
157 ms |
16632 KB |
Output is correct |
10 |
Correct |
158 ms |
16632 KB |
Output is correct |
11 |
Correct |
158 ms |
16632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
896 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
106 ms |
6520 KB |
Output is correct |
9 |
Correct |
109 ms |
6392 KB |
Output is correct |
10 |
Correct |
106 ms |
6776 KB |
Output is correct |
11 |
Correct |
106 ms |
7288 KB |
Output is correct |
12 |
Correct |
96 ms |
6008 KB |
Output is correct |
13 |
Correct |
103 ms |
6648 KB |
Output is correct |
14 |
Correct |
102 ms |
6648 KB |
Output is correct |
15 |
Correct |
101 ms |
6648 KB |
Output is correct |
16 |
Correct |
95 ms |
6460 KB |
Output is correct |
17 |
Correct |
102 ms |
6648 KB |
Output is correct |
18 |
Correct |
102 ms |
6648 KB |
Output is correct |
19 |
Correct |
101 ms |
6652 KB |
Output is correct |
20 |
Correct |
98 ms |
6648 KB |
Output is correct |
21 |
Correct |
96 ms |
6392 KB |
Output is correct |
22 |
Correct |
100 ms |
6520 KB |
Output is correct |
23 |
Correct |
104 ms |
6452 KB |
Output is correct |
24 |
Correct |
105 ms |
6392 KB |
Output is correct |
25 |
Correct |
103 ms |
6392 KB |
Output is correct |
26 |
Correct |
105 ms |
6392 KB |
Output is correct |
27 |
Correct |
192 ms |
18160 KB |
Output is correct |
28 |
Correct |
212 ms |
18040 KB |
Output is correct |
29 |
Correct |
188 ms |
17736 KB |
Output is correct |
30 |
Correct |
193 ms |
18196 KB |
Output is correct |
31 |
Correct |
208 ms |
18168 KB |
Output is correct |
32 |
Correct |
156 ms |
16888 KB |
Output is correct |
33 |
Correct |
155 ms |
16760 KB |
Output is correct |
34 |
Correct |
160 ms |
16632 KB |
Output is correct |
35 |
Correct |
157 ms |
16632 KB |
Output is correct |
36 |
Correct |
158 ms |
16632 KB |
Output is correct |
37 |
Correct |
158 ms |
16632 KB |
Output is correct |
38 |
Correct |
299 ms |
46616 KB |
Output is correct |
39 |
Correct |
311 ms |
54432 KB |
Output is correct |
40 |
Correct |
277 ms |
37240 KB |
Output is correct |
41 |
Correct |
307 ms |
52856 KB |
Output is correct |
42 |
Correct |
166 ms |
17912 KB |
Output is correct |
43 |
Correct |
165 ms |
17916 KB |
Output is correct |
44 |
Correct |
230 ms |
28920 KB |
Output is correct |
45 |
Correct |
228 ms |
28792 KB |
Output is correct |
46 |
Correct |
233 ms |
29048 KB |
Output is correct |
47 |
Correct |
166 ms |
17788 KB |
Output is correct |
48 |
Correct |
161 ms |
17656 KB |
Output is correct |
49 |
Correct |
232 ms |
28664 KB |
Output is correct |
50 |
Correct |
227 ms |
28664 KB |
Output is correct |
51 |
Correct |
233 ms |
29048 KB |
Output is correct |
52 |
Correct |
206 ms |
27640 KB |
Output is correct |
53 |
Correct |
257 ms |
37496 KB |
Output is correct |
54 |
Correct |
300 ms |
47480 KB |
Output is correct |
55 |
Correct |
280 ms |
37624 KB |
Output is correct |