제출 #1291477

#제출 시각아이디문제언어결과실행 시간메모리
1291477kkkkLong Mansion (JOI17_long_mansion)C++20
0 / 100
2065 ms5596 KiB
#include<bits/stdc++.h> using namespace std; const int N = 5e5+5; int n,a[N],c[N],L[N],R[N]; vector<int> d[N]; bool check(int l,int r,int v) { if(d[v].empty()) return 0; auto it = lower_bound(d[v].begin(),d[v].end(),l); if(it == d[v].end()) return 0; return *it <= r; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for(int i = 1;i < n;i++) cin>>c[i]; for(int i = 1;i <= n;i++) { int x; cin>>x; for(int j = 1;j <= x;j++) { int r; cin>>r; d[r].push_back(i); } } for(int i = 1;i <= n;i++) { bool cc = 1; int x = i,y = i; while(cc and x >= 1 and y <= n) { cc = 0; if(check(x,y,c[x-1])) { x = min(x,L[x-1]); y = max(y,R[x-1]); cc = 1; } if(check(x,y,c[y])) { y++; cc = 1; } } L[i] = x; R[i] = y; } int q; cin>>q; while(q--) { int l,r; cin>>l>>r; if(L[l] <= r and r <= R[l]) cout<<"YES"<<'\n'; else cout<<"NO"<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...