//Be Name Khoda
#include<bits/stdc++.h>
#pragma GCC target ("avx2,tune=native")
using namespace std;
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define plll pair<pll, ll>
const ll mxn = 5e5 + 16, INF = 1LL * 1e17 + 32;
ll n, t, k, q;
ll c[mxn];
pll ans[mxn];
vector<ll> keys[mxn];
void input() {
cin >> n;
for(int i = 1; i < n; i++) {
cin >> c[i];
}
for(int i = 1; i <= n; i++) {
cin >> k;
for(int j = 0; j < k; j++) {
cin >> q;
keys[i].push_back(q);
}
} cin >> t;
}
inline void merge(int l, int r, int m) {
unordered_set<int> s;
bool mark[r - l + 5];
int tmp[r - l + 5];
int pr = m, pl = m - 1;
memset(mark, 0, sizeof(mark));
for(int i = m - 1; i > l - 1; i--) {
for(auto u : keys[i]) s.insert(u);
while(pr < r) {
if(s.count(c[pr - 1])) {
for(auto u : keys[pr]) s.insert(u);
pr++;
}
else break;
}
tmp[i - l] = pr;
if(i > l) {
if(s.count(c[i - 1])) mark[i - l] = 1;
}
}
for(int i = l; i < m; i++) {
if(mark[i - l]) continue;
if(ans[i].second >= m) {
ans[i].second = tmp[i - l];
}
for(int j = i + 1; j < m; j++) {
if(!mark[j - l]) break;
if(ans[j].second < m) continue;
ans[j].first = i, ans[j].second = tmp[i - l];
}
}
s.clear();
for(int i = m; i < r; i++) {
for(auto u : keys[i]) s.insert(u);
while(pl > l - 1) {
if(s.count(c[pl])) {
for(auto u : keys[pl]) s.insert(u);
pl--;
}
else break;
}
tmp[i - l] = pl + 1;
if(i < r - 1) {
if(s.count(c[i])) mark[i - l] = 1;
}
}
for(int i = r - 1; i > m - 1; i--) {
if(mark[i - l]) continue;
if(ans[i].first <= m) {
ans[i].first = tmp[i - l];
}
for(int j = i - 1; j > m - 1; j--) {
if(!mark[j - l]) continue;
if(ans[j].first > m) continue;
ans[j].first = tmp[i - l], ans[j].second = i + 1;
}
}
return;
}
void solve(int l, int r) {
if(r - l == 1) {
ans[l] = make_pair(l, r);
return;
}
int m = (l + r) >> 1;
solve(l, m); solve(m, r);
merge(l, r, m);
return;
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
input(), solve(1, n + 1);
for(int i = 0; i < t; i++) {
int x, y;
cin >> x >> y;
if(y < ans[x].first || ans[x].second <= y) {
cout << "NO\n";
continue;
}
cout << "YES\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12228 KB |
Output is correct |
2 |
Correct |
11 ms |
12336 KB |
Output is correct |
3 |
Correct |
14 ms |
12468 KB |
Output is correct |
4 |
Correct |
12 ms |
12212 KB |
Output is correct |
5 |
Correct |
10 ms |
12236 KB |
Output is correct |
6 |
Correct |
11 ms |
12236 KB |
Output is correct |
7 |
Correct |
10 ms |
12264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12228 KB |
Output is correct |
2 |
Correct |
11 ms |
12336 KB |
Output is correct |
3 |
Correct |
14 ms |
12468 KB |
Output is correct |
4 |
Correct |
12 ms |
12212 KB |
Output is correct |
5 |
Correct |
10 ms |
12236 KB |
Output is correct |
6 |
Correct |
11 ms |
12236 KB |
Output is correct |
7 |
Correct |
10 ms |
12264 KB |
Output is correct |
8 |
Correct |
94 ms |
18044 KB |
Output is correct |
9 |
Correct |
88 ms |
18060 KB |
Output is correct |
10 |
Correct |
106 ms |
18492 KB |
Output is correct |
11 |
Correct |
94 ms |
18736 KB |
Output is correct |
12 |
Correct |
81 ms |
17680 KB |
Output is correct |
13 |
Correct |
91 ms |
18248 KB |
Output is correct |
14 |
Correct |
91 ms |
18276 KB |
Output is correct |
15 |
Correct |
95 ms |
18208 KB |
Output is correct |
16 |
Correct |
90 ms |
18072 KB |
Output is correct |
17 |
Correct |
98 ms |
18248 KB |
Output is correct |
18 |
Correct |
92 ms |
18256 KB |
Output is correct |
19 |
Correct |
90 ms |
18392 KB |
Output is correct |
20 |
Correct |
91 ms |
18216 KB |
Output is correct |
21 |
Correct |
91 ms |
18092 KB |
Output is correct |
22 |
Correct |
98 ms |
18180 KB |
Output is correct |
23 |
Correct |
88 ms |
18128 KB |
Output is correct |
24 |
Correct |
110 ms |
18116 KB |
Output is correct |
25 |
Correct |
94 ms |
18160 KB |
Output is correct |
26 |
Correct |
97 ms |
18076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
385 ms |
29740 KB |
Output is correct |
2 |
Correct |
405 ms |
29544 KB |
Output is correct |
3 |
Correct |
366 ms |
29060 KB |
Output is correct |
4 |
Correct |
403 ms |
29620 KB |
Output is correct |
5 |
Correct |
396 ms |
29552 KB |
Output is correct |
6 |
Correct |
280 ms |
26508 KB |
Output is correct |
7 |
Correct |
273 ms |
26104 KB |
Output is correct |
8 |
Correct |
259 ms |
26048 KB |
Output is correct |
9 |
Correct |
258 ms |
26032 KB |
Output is correct |
10 |
Correct |
291 ms |
26104 KB |
Output is correct |
11 |
Correct |
269 ms |
26040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12228 KB |
Output is correct |
2 |
Correct |
11 ms |
12336 KB |
Output is correct |
3 |
Correct |
14 ms |
12468 KB |
Output is correct |
4 |
Correct |
12 ms |
12212 KB |
Output is correct |
5 |
Correct |
10 ms |
12236 KB |
Output is correct |
6 |
Correct |
11 ms |
12236 KB |
Output is correct |
7 |
Correct |
10 ms |
12264 KB |
Output is correct |
8 |
Correct |
94 ms |
18044 KB |
Output is correct |
9 |
Correct |
88 ms |
18060 KB |
Output is correct |
10 |
Correct |
106 ms |
18492 KB |
Output is correct |
11 |
Correct |
94 ms |
18736 KB |
Output is correct |
12 |
Correct |
81 ms |
17680 KB |
Output is correct |
13 |
Correct |
91 ms |
18248 KB |
Output is correct |
14 |
Correct |
91 ms |
18276 KB |
Output is correct |
15 |
Correct |
95 ms |
18208 KB |
Output is correct |
16 |
Correct |
90 ms |
18072 KB |
Output is correct |
17 |
Correct |
98 ms |
18248 KB |
Output is correct |
18 |
Correct |
92 ms |
18256 KB |
Output is correct |
19 |
Correct |
90 ms |
18392 KB |
Output is correct |
20 |
Correct |
91 ms |
18216 KB |
Output is correct |
21 |
Correct |
91 ms |
18092 KB |
Output is correct |
22 |
Correct |
98 ms |
18180 KB |
Output is correct |
23 |
Correct |
88 ms |
18128 KB |
Output is correct |
24 |
Correct |
110 ms |
18116 KB |
Output is correct |
25 |
Correct |
94 ms |
18160 KB |
Output is correct |
26 |
Correct |
97 ms |
18076 KB |
Output is correct |
27 |
Correct |
385 ms |
29740 KB |
Output is correct |
28 |
Correct |
405 ms |
29544 KB |
Output is correct |
29 |
Correct |
366 ms |
29060 KB |
Output is correct |
30 |
Correct |
403 ms |
29620 KB |
Output is correct |
31 |
Correct |
396 ms |
29552 KB |
Output is correct |
32 |
Correct |
280 ms |
26508 KB |
Output is correct |
33 |
Correct |
273 ms |
26104 KB |
Output is correct |
34 |
Correct |
259 ms |
26048 KB |
Output is correct |
35 |
Correct |
258 ms |
26032 KB |
Output is correct |
36 |
Correct |
291 ms |
26104 KB |
Output is correct |
37 |
Correct |
269 ms |
26040 KB |
Output is correct |
38 |
Execution timed out |
3007 ms |
37660 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |