#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ff first
#define ss second
#define N 524288
#define MOD 1000000007
#define INF 0x3f3f3f3f
int c[N];
int n;
vector<int> loc[N];
int le[N], ri[N];
bool query(int l, int r, int c){
auto it = lower_bound(loc[c].begin(), loc[c].end(), l);
return it != loc[c].end() && *it <= r;
}
void dnc(int l, int r){
if(l > r) return;
int m = (l + r) >> 1;
int L = m, R = m;
bool ok;
do {
ok = 0;
while(query(L, R, c[R])){
++R;
ok = 1;
if(ri[R]){
L = min(L, le[R]);
R = max(R, ri[R]);
}
}
while(query(L, R, c[L - 1])){
--L;
ok = 1;
if(le[L]){
R = max(R, ri[L]);
L = min(L, le[L]);
}
}
} while (ok == 1);
le[m] = L;
ri[m] = R;
dnc(l, m - 1);
dnc(m + 1, r);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i = 1; i < n; ++i){
cin>>c[i];
}
for(int b, k, i = 1; i <= n; ++i){
cin>>b;
while(b--){
cin>>k;
loc[k].push_back(i);
}
}
dnc(1, n);
int q;
cin>>q;
while(q--){
int x, y;
cin>>x>>y;
if(le[x] <= y && y <= ri[x])
cout<<"YES\n";
else
cout<<"NO\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
12920 KB |
Output is correct |
2 |
Correct |
17 ms |
12792 KB |
Output is correct |
3 |
Correct |
27 ms |
12920 KB |
Output is correct |
4 |
Correct |
15 ms |
12792 KB |
Output is correct |
5 |
Correct |
15 ms |
12792 KB |
Output is correct |
6 |
Correct |
15 ms |
12920 KB |
Output is correct |
7 |
Correct |
14 ms |
12920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
12920 KB |
Output is correct |
2 |
Correct |
17 ms |
12792 KB |
Output is correct |
3 |
Correct |
27 ms |
12920 KB |
Output is correct |
4 |
Correct |
15 ms |
12792 KB |
Output is correct |
5 |
Correct |
15 ms |
12792 KB |
Output is correct |
6 |
Correct |
15 ms |
12920 KB |
Output is correct |
7 |
Correct |
14 ms |
12920 KB |
Output is correct |
8 |
Correct |
138 ms |
14712 KB |
Output is correct |
9 |
Correct |
122 ms |
14464 KB |
Output is correct |
10 |
Correct |
128 ms |
14584 KB |
Output is correct |
11 |
Correct |
126 ms |
14716 KB |
Output is correct |
12 |
Correct |
111 ms |
14584 KB |
Output is correct |
13 |
Correct |
117 ms |
14584 KB |
Output is correct |
14 |
Correct |
122 ms |
14712 KB |
Output is correct |
15 |
Correct |
119 ms |
14712 KB |
Output is correct |
16 |
Correct |
121 ms |
14844 KB |
Output is correct |
17 |
Correct |
122 ms |
14584 KB |
Output is correct |
18 |
Correct |
120 ms |
14584 KB |
Output is correct |
19 |
Correct |
121 ms |
14584 KB |
Output is correct |
20 |
Correct |
122 ms |
14712 KB |
Output is correct |
21 |
Correct |
118 ms |
14844 KB |
Output is correct |
22 |
Correct |
120 ms |
14712 KB |
Output is correct |
23 |
Correct |
127 ms |
14532 KB |
Output is correct |
24 |
Correct |
125 ms |
14456 KB |
Output is correct |
25 |
Correct |
119 ms |
14584 KB |
Output is correct |
26 |
Correct |
122 ms |
14456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3070 ms |
16632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
12920 KB |
Output is correct |
2 |
Correct |
17 ms |
12792 KB |
Output is correct |
3 |
Correct |
27 ms |
12920 KB |
Output is correct |
4 |
Correct |
15 ms |
12792 KB |
Output is correct |
5 |
Correct |
15 ms |
12792 KB |
Output is correct |
6 |
Correct |
15 ms |
12920 KB |
Output is correct |
7 |
Correct |
14 ms |
12920 KB |
Output is correct |
8 |
Correct |
138 ms |
14712 KB |
Output is correct |
9 |
Correct |
122 ms |
14464 KB |
Output is correct |
10 |
Correct |
128 ms |
14584 KB |
Output is correct |
11 |
Correct |
126 ms |
14716 KB |
Output is correct |
12 |
Correct |
111 ms |
14584 KB |
Output is correct |
13 |
Correct |
117 ms |
14584 KB |
Output is correct |
14 |
Correct |
122 ms |
14712 KB |
Output is correct |
15 |
Correct |
119 ms |
14712 KB |
Output is correct |
16 |
Correct |
121 ms |
14844 KB |
Output is correct |
17 |
Correct |
122 ms |
14584 KB |
Output is correct |
18 |
Correct |
120 ms |
14584 KB |
Output is correct |
19 |
Correct |
121 ms |
14584 KB |
Output is correct |
20 |
Correct |
122 ms |
14712 KB |
Output is correct |
21 |
Correct |
118 ms |
14844 KB |
Output is correct |
22 |
Correct |
120 ms |
14712 KB |
Output is correct |
23 |
Correct |
127 ms |
14532 KB |
Output is correct |
24 |
Correct |
125 ms |
14456 KB |
Output is correct |
25 |
Correct |
119 ms |
14584 KB |
Output is correct |
26 |
Correct |
122 ms |
14456 KB |
Output is correct |
27 |
Execution timed out |
3070 ms |
16632 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |