이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
/* sorry, this is the bare minimum :'( */
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second
int main(int argc, char const *argv[])
{
cin.sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int n; cin >> n;
vi C(n-1);
for(int i = 0; i < n-1; ++i) {
cin >> C[i];
C[i]--;
}
using bs = bitset<50>;
vector<bs> A(n);
for(int i = 0; i < n; ++i) {
int k; cin >> k;
while(k--) {
int x; cin >> x;
x--;
A[i][x] = 1;
}
}
vector<ii> ra(n);
for(int i = 0; i < n; ++i) {
int l = i, r = i;
bs has = A[i];
while(true) {
int flag = 0;
if(l and has[C[l-1]]) {
has |= A[--l];
++flag;
}
if(r < n-1 and has[C[r]]) {
has |= A[++r];
++flag;
}
if(!flag) break;
}
// cout << l+1 << ' ' << r+1 << endl;
ra[i] = {l, r};
}
int q; cin >> q;
while(q--) {
int x, y;
cin >> x >> y;
--x, --y;
cout << (ra[x].fi <= y and y <= ra[x].se ? "YES" : "NO") << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |