Submission #1209044

#TimeUsernameProblemLanguageResultExecution timeMemory
1209044mychecksedadLong Mansion (JOI17_long_mansion)C++20
10 / 100
90 ms2632 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; #define ll long long int #define MOD (1000000000+7) #define MOD1 (998244353) #define pb push_back #define all(x) x.begin(), x.end() #define en cout << '\n' #define ff first #define ss second #define pii pair<int,int> #define vi vector<int> const int N = 5e3+100, M = 1e5+10, K = 21, MX = 30; int n, c[N], L[N][K], R[N][K]; vector<int> A[N]; array<int, 2> a[N]; void solve(){ cin >> n; for(int i = 1; i < n; ++i){ cin >> c[i]; } for(int i = 1; i <= n; ++i){ int x; cin >> x; A[i].resize(x); for(int &y: A[i]) cin >> y; } // for(int i = 1; i < K; ++i){ // L[1][i] = 1; // } // for(int i = 2; i <= n; ++i){ // for(int j = 1; j < K; ++j) L[i][j] = L[i - 1][j]; // L[i][c[i - 1]] = i; // } // for(int i = 1; i < K; ++i){ // R[n][i] = n; // } // for(int i = n - 1; i >= 1; --i){ // for(int j = 1; j < K; ++j) R[i][j] = R[i + 1][j]; // R[i][c[i]] = i; // } for(int i = 1; i <= n; ++i){ a[i][0] = i, a[i][1] = i; bool ok = 1; vector<int> keys(n + 1); for(int x: A[i]) keys[x] = 1; while(ok){ ok = 0; if(a[i][0] > 1 && keys[c[a[i][0] - 1]]){ --a[i][0]; for(int x: A[a[i][0]]) keys[x] = 1; ok = 1; }else if(a[i][1] < n && keys[c[a[i][1]]]){ ++a[i][1]; for(int x: A[a[i][1]]) keys[x] = 1; ok = 1; } } } int q; cin >> q; for(int i = 1; i <= q; ++i){ int x, y; cin >> x >> y; if(a[x][0] <= y && a[x][1] >= y){ cout << "YES\n"; }else{ cout << "NO\n"; } } } int main(){ cin.tie(0); ios::sync_with_stdio(0); int tt = 1, aa; // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); while(tt--){ solve(); } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...