// author : thembululquaUwU
// 3.9.2024
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int N = 5e5 + 5;
const int mod = 1e9 + 7;
void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}
int n, q, c[N], pos[N], le[N], ri[N];
vector <int> keys[N], event[N];
struct Segtree{
int Min[N << 2], inf;
Segtree () {
for (int i = 1; i <= 4 * n; ++ i) Min[i] = inf;
}
void fix(int u, int val, int s = 1, int l = 1, int r = n){
if (l == r){
Min[s] = val; return;
}
int mid = l + r >> 1;
if (mid >= u) fix(u, val, s << 1, l, mid);
else fix(u, val, s << 1 | 1, mid + 1, r);
if (inf == mod) Min[s] = min(Min[s << 1], Min[s << 1 | 1]);
else Min[s] = max(Min[s << 1], Min[s << 1 | 1]);
}
int get(int u, int v, int s = 1, int l = 1, int r = n){
if (u > r || v < l) return inf;
if (u <= l && r <= v) return Min[s];
int mid = l + r >> 1;
if (inf == mod) return min(get(u, v, s << 1, l, mid), get(u, v, s << 1 | 1, mid + 1, r));
return max(get(u, v, s << 1, l, mid), get(u, v, s << 1 | 1, mid + 1, r));
}
} T1, T2, T3, T4;
void solve_left(){
for (int i = 1; i <= n; ++ i){
event[ri[i]].pb(i); T1.fix(i, i);
for (auto k : event[i]) T1.fix(k, mod);
if (le[i] < i) T2.fix(i, T1.get(le[i] + 1, i));
event[i].clear();
}
}
void solve_right(){
for (int i = n; i >= 1; -- i){
event[le[i]].pb(i); T3.fix(i, i);
for (auto k : event[i]) T3.fix(k, -mod);
if (i < ri[i]) T4.fix(i, T3.get(i, ri[i] - 1));
event[i].clear();
}
}
void solve(){
cin >> n; T1.inf = T2.inf = mod; T3.inf = T4.inf = -mod;
for (int i = 1; i < n; ++ i) cin >> c[i];
for (int i = 1; i <= n; ++ i){
int b; cin >> b;
while (b --){
int a; cin >> a; keys[i].pb(a);
}
}
for (int i = 1; i <= n; ++ i) pos[i] = n + 1;
for (int i = n; i >= 1; -- i){
for (auto k : keys[i]) pos[k] = i;
if (i > 1) ri[i] = pos[c[i - 1]]; else ri[i] = n + 1;
}
for (int i = 1; i <= n; ++ i) pos[i] = 0;
for (int i = 1; i <= n; ++ i){
for (auto k : keys[i]) pos[k] = i;
if (i < n) le[i] = pos[c[i]]; else le[i] = 0;
}
solve_left(); solve_right();
cin >> q;
while (q --){
int l, r; cin >> l >> r;
if (l < r){
if (T2.get(l, r - 1) <= l) cout << "NO" << endl;
else cout << "YES" << endl;
}
else {
if (T4.get(r + 1, l) >= l) cout << "NO" << endl;
else cout << "YES" << endl;
}
}
}
int main(){
if (fopen("pqh.inp", "r")){
freopen("pqh.inp", "r", stdin);
freopen("pqh.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while (t --) solve();
return 0;
}
Compilation message
long_mansion.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
18 | void maxl(auto &a, auto b) {a = max(a, b);}
| ^~~~
long_mansion.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
18 | void maxl(auto &a, auto b) {a = max(a, b);}
| ^~~~
long_mansion.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void minl(auto &a, auto b) {a = min(a, b);}
| ^~~~
long_mansion.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void minl(auto &a, auto b) {a = min(a, b);}
| ^~~~
long_mansion.cpp: In member function 'void Segtree::fix(int, int, int, int, int)':
long_mansion.cpp:37:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | int mid = l + r >> 1;
| ~~^~~
long_mansion.cpp: In member function 'int Segtree::get(int, int, int, int, int)':
long_mansion.cpp:48:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int mid = l + r >> 1;
| ~~^~~
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:112:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
112 | freopen("pqh.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | freopen("pqh.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp: In function '(static initializers for long_mansion.cpp)':
long_mansion.cpp:29:52: warning: 'T1.Segtree::inf' may be used uninitialized in this function [-Wmaybe-uninitialized]
29 | for (int i = 1; i <= 4 * n; ++ i) Min[i] = inf;
| ^~~
long_mansion.cpp:29:52: warning: 'T4.Segtree::inf' may be used uninitialized in this function [-Wmaybe-uninitialized]
29 | for (int i = 1; i <= 4 * n; ++ i) Min[i] = inf;
| ^~~
long_mansion.cpp:29:52: warning: 'T3.Segtree::inf' may be used uninitialized in this function [-Wmaybe-uninitialized]
29 | for (int i = 1; i <= 4 * n; ++ i) Min[i] = inf;
| ^~~
long_mansion.cpp:29:52: warning: 'T2.Segtree::inf' may be used uninitialized in this function [-Wmaybe-uninitialized]
29 | for (int i = 1; i <= 4 * n; ++ i) Min[i] = inf;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
24152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
24152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
295 ms |
44872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
24152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |