Submission #1209065

#TimeUsernameProblemLanguageResultExecution timeMemory
1209065mychecksedadLong Mansion (JOI17_long_mansion)C++20
100 / 100
232 ms39436 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 = 5e5+100, M = 1e5+10, K = 21, MX = 30; mt19937 rng(342236234); int rn(int l, int r){ return uniform_int_distribution<int>(l,r)(rng); } int n, c[N], used[N], ptr; vector<int> A[N]; array<int, 2> a[N]; bitset<N> keys; 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; } vi v; for(int i = 1; i <= n; ++i){ v.pb(i); swap(v[i-1], v[rn(0, i-1)]); } ptr = 0; vector<bool> done(n + 1); for(int j = 1; j <= n; ++j){ int i = v[j - 1]; done[i] = 1; for(int y = 0; y < ptr; ++y) keys[used[y]] = 0; ptr = 0; for(int y = 0; y < A[i].size(); ++y) used[ptr++] = A[i][y], keys[A[i][y]] = 1; a[i][0] = i, a[i][1] = i; bool ok = 1; while(ok){ ok = 0; if(a[i][0] > 1 && keys[c[a[i][0] - 1]]){ --a[i][0]; if(done[a[i][0]] && a[a[i][0]][1] >= i){ a[i] = a[a[i][0]]; break; } for(int x: A[a[i][0]]) keys[x] = 1, used[ptr++] = x; ok = 1; }else if(a[i][1] < n && keys[c[a[i][1]]]){ ++a[i][1]; if(done[a[i][1]] && a[a[i][1]][0] <= i){ a[i] = a[a[i][1]]; break; } for(int x: A[a[i][1]]) keys[x] = 1, used[ptr++] = x; ok = 1; } } // cerr << a[i][0] << ' ' << a[i][1] << '\n'; } 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...