#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1 << 20;
int last[N];
int l[N << 2], r[N << 2];
void upd(int v, int tl, int tr, int ql, int qr) {
if (tr < ql || qr < tl) {
return;
}
if (ql <= tl && tr <= qr) {
l[v] = max(l[v], ql);
r[v] = min(r[v], qr);
return;
}
int tm = (tl + tr) >> 1;
upd(v * 2 + 1, tl, tm, ql, qr);
upd(v * 2 + 2, tm + 1, tr, ql, qr);
}
void write(int v, int tl, int tr, vector <int> &al, vector <int> &ar) {
if (tl == tr) {
al[tl] = l[v];
ar[tl] = r[v];
return;
}
int tm = (tl + tr) >> 1;
l[v * 2 + 1] = max(l[v * 2 + 1], l[v]);
l[v * 2 + 2] = max(l[v * 2 + 2], l[v]);
r[v * 2 + 1] = min(r[v * 2 + 1], r[v]);
r[v * 2 + 2] = min(r[v * 2 + 2], r[v]);
write(v * 2 + 1, tl, tm, al, ar);
write(v * 2 + 2, tm + 1, tr, al, ar);
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n;
cin >> n;
for (int i = 0; i < (N << 2); ++i)
r[i] = n - 1;
vector <int> c(n-1);
for (int i = 0; i < n - 1; ++i)
cin >> c[i];
vector <vector <int> > a(n);
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
a[i].resize(k);
for (int j = 0; j < k; ++j)
cin >> a[i][j];
}
vector <int> l(n), r(n);
for (int i = 0; i < n; ++i) {
l[i] = 0;
r[i] = n - 1;
}
vector <int> linkl(n), linkr(n);
for (int i = 0; i < N; ++i)
last[i] = -1;
for (int i = 0; i < n - 1; ++i) {
for (auto e : a[i])
last[e] = i;
linkl[i] = last[c[i]]+1;
}
for (int i = 0; i < N; ++i)
last[i] = n;
for (int i = n - 1; i >= 0; --i) {
if (i < n - 1) {
linkr[i] = last[c[i]]-1;
}
for (auto e : a[i])
last[e] = i;
}
for (int i = 0; i < n; ++i) {
for (int j = linkr[i]; j>=i; --j) {
if (linkl[j] <= i+1) {
upd(0, 0, n - 1, i+1, j);
break;
}
}
}
for (int j = 0; j < n; ++j) {
for (int i = linkl[j]-1; i <= j; ++i) {
if (j <= linkr[i]) {
upd(0, 0, n - 1, i+1, j);
break;
}
}
}
for (int i = 0; i < n; ++i) {
if (linkr[i] == n - 1) {
upd(0, 0, n - 1, i+1, n - 1);
}
}
for (int i = 0; i < n; ++i) {
if (linkl[i] == 0) {
upd(0, 0, n - 1, 0, i);
}
}
write(0, 0, n - 1, l, r);
int q;
cin >> q;
while (q--) {
int i, j;
cin >> i >> j;
--i; --j;
if (l[i] <= j && j <= r[i]) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
21120 KB |
Output is correct |
2 |
Correct |
19 ms |
21248 KB |
Output is correct |
3 |
Correct |
20 ms |
21376 KB |
Output is correct |
4 |
Correct |
20 ms |
21120 KB |
Output is correct |
5 |
Correct |
19 ms |
21120 KB |
Output is correct |
6 |
Correct |
19 ms |
21120 KB |
Output is correct |
7 |
Correct |
22 ms |
21120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
21120 KB |
Output is correct |
2 |
Correct |
19 ms |
21248 KB |
Output is correct |
3 |
Correct |
20 ms |
21376 KB |
Output is correct |
4 |
Correct |
20 ms |
21120 KB |
Output is correct |
5 |
Correct |
19 ms |
21120 KB |
Output is correct |
6 |
Correct |
19 ms |
21120 KB |
Output is correct |
7 |
Correct |
22 ms |
21120 KB |
Output is correct |
8 |
Correct |
140 ms |
25208 KB |
Output is correct |
9 |
Correct |
137 ms |
24952 KB |
Output is correct |
10 |
Correct |
133 ms |
25208 KB |
Output is correct |
11 |
Correct |
139 ms |
25464 KB |
Output is correct |
12 |
Correct |
127 ms |
25208 KB |
Output is correct |
13 |
Correct |
133 ms |
25208 KB |
Output is correct |
14 |
Correct |
137 ms |
25208 KB |
Output is correct |
15 |
Correct |
140 ms |
25400 KB |
Output is correct |
16 |
Correct |
136 ms |
25464 KB |
Output is correct |
17 |
Correct |
143 ms |
25208 KB |
Output is correct |
18 |
Correct |
138 ms |
25184 KB |
Output is correct |
19 |
Correct |
132 ms |
25292 KB |
Output is correct |
20 |
Correct |
131 ms |
25336 KB |
Output is correct |
21 |
Correct |
134 ms |
25464 KB |
Output is correct |
22 |
Correct |
140 ms |
25208 KB |
Output is correct |
23 |
Correct |
135 ms |
25080 KB |
Output is correct |
24 |
Correct |
139 ms |
25080 KB |
Output is correct |
25 |
Correct |
139 ms |
25080 KB |
Output is correct |
26 |
Correct |
136 ms |
25080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
35320 KB |
Output is correct |
2 |
Correct |
245 ms |
33528 KB |
Output is correct |
3 |
Correct |
243 ms |
33660 KB |
Output is correct |
4 |
Correct |
238 ms |
33528 KB |
Output is correct |
5 |
Correct |
248 ms |
33656 KB |
Output is correct |
6 |
Correct |
223 ms |
33640 KB |
Output is correct |
7 |
Correct |
214 ms |
33912 KB |
Output is correct |
8 |
Correct |
212 ms |
33784 KB |
Output is correct |
9 |
Correct |
209 ms |
33784 KB |
Output is correct |
10 |
Correct |
211 ms |
33796 KB |
Output is correct |
11 |
Correct |
210 ms |
33784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
21120 KB |
Output is correct |
2 |
Correct |
19 ms |
21248 KB |
Output is correct |
3 |
Correct |
20 ms |
21376 KB |
Output is correct |
4 |
Correct |
20 ms |
21120 KB |
Output is correct |
5 |
Correct |
19 ms |
21120 KB |
Output is correct |
6 |
Correct |
19 ms |
21120 KB |
Output is correct |
7 |
Correct |
22 ms |
21120 KB |
Output is correct |
8 |
Correct |
140 ms |
25208 KB |
Output is correct |
9 |
Correct |
137 ms |
24952 KB |
Output is correct |
10 |
Correct |
133 ms |
25208 KB |
Output is correct |
11 |
Correct |
139 ms |
25464 KB |
Output is correct |
12 |
Correct |
127 ms |
25208 KB |
Output is correct |
13 |
Correct |
133 ms |
25208 KB |
Output is correct |
14 |
Correct |
137 ms |
25208 KB |
Output is correct |
15 |
Correct |
140 ms |
25400 KB |
Output is correct |
16 |
Correct |
136 ms |
25464 KB |
Output is correct |
17 |
Correct |
143 ms |
25208 KB |
Output is correct |
18 |
Correct |
138 ms |
25184 KB |
Output is correct |
19 |
Correct |
132 ms |
25292 KB |
Output is correct |
20 |
Correct |
131 ms |
25336 KB |
Output is correct |
21 |
Correct |
134 ms |
25464 KB |
Output is correct |
22 |
Correct |
140 ms |
25208 KB |
Output is correct |
23 |
Correct |
135 ms |
25080 KB |
Output is correct |
24 |
Correct |
139 ms |
25080 KB |
Output is correct |
25 |
Correct |
139 ms |
25080 KB |
Output is correct |
26 |
Correct |
136 ms |
25080 KB |
Output is correct |
27 |
Correct |
236 ms |
35320 KB |
Output is correct |
28 |
Correct |
245 ms |
33528 KB |
Output is correct |
29 |
Correct |
243 ms |
33660 KB |
Output is correct |
30 |
Correct |
238 ms |
33528 KB |
Output is correct |
31 |
Correct |
248 ms |
33656 KB |
Output is correct |
32 |
Correct |
223 ms |
33640 KB |
Output is correct |
33 |
Correct |
214 ms |
33912 KB |
Output is correct |
34 |
Correct |
212 ms |
33784 KB |
Output is correct |
35 |
Correct |
209 ms |
33784 KB |
Output is correct |
36 |
Correct |
211 ms |
33796 KB |
Output is correct |
37 |
Correct |
210 ms |
33784 KB |
Output is correct |
38 |
Correct |
585 ms |
65436 KB |
Output is correct |
39 |
Correct |
602 ms |
75132 KB |
Output is correct |
40 |
Correct |
434 ms |
59384 KB |
Output is correct |
41 |
Correct |
438 ms |
73464 KB |
Output is correct |
42 |
Correct |
244 ms |
38552 KB |
Output is correct |
43 |
Correct |
245 ms |
38776 KB |
Output is correct |
44 |
Correct |
322 ms |
49784 KB |
Output is correct |
45 |
Correct |
333 ms |
49836 KB |
Output is correct |
46 |
Correct |
324 ms |
49912 KB |
Output is correct |
47 |
Correct |
236 ms |
38648 KB |
Output is correct |
48 |
Correct |
232 ms |
38524 KB |
Output is correct |
49 |
Correct |
311 ms |
49656 KB |
Output is correct |
50 |
Correct |
317 ms |
49784 KB |
Output is correct |
51 |
Correct |
323 ms |
50040 KB |
Output is correct |
52 |
Execution timed out |
3072 ms |
40864 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |