제출 #204741

#제출 시각아이디문제언어결과실행 시간메모리
204741hanagasumiLong Mansion (JOI17_long_mansion)C++17
10 / 100
3078 ms17220 KiB
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <deque> #include <map> #include <set> #include <complex> #include <string> #include <unordered_map> #include <unordered_set> #include <random> #include <chrono> #define ft first #define sc second #define pb push_back #define len(v) (int)v.size() #define int ll using namespace std; typedef long long ll; typedef long double ld; signed main() { #ifdef PC freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> per(n); vector<vector<int>> keys(n); vector<vector<int>> types(n); for (int i = 1; i < n; i++) { cin >> per[i]; if(per[i] > n || per[i] == 0) return -1; per[i]--; } for (int i = 0; i < n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int x; cin >> x; if(x > n || x == 0) return -1; x--; types[x].pb(i); keys[i].pb(x); } } //calc v<>l // for (int i = 0; i < n; i++) { // l[i] = 0; // map<int, bool> have; // for (int j = i; j > 0; j--) { // for (auto x : keys[j]) // have[x] = 1; // if(!have[per[j]]) { // l[i] = j; // break; // } // } // } // calc ans vector<pair<int, int>> ans(n); for (int i = n - 1; i >= 0; i--) { int ln = i, rn = i + 1; while(1) { bool flag = 1; if(ln > 0) { auto uk = lower_bound(types[per[ln]].begin(), types[per[ln]].end(), ln); if(uk != types[per[ln]].end() && (*uk < rn)) { ln--; flag = 0; } } if(rn < n) { auto uk = lower_bound(types[per[rn]].begin(), types[per[rn]].end(), rn); if(uk != types[per[rn]].begin()) { uk--; if(*uk >= ln) { rn++; flag = 0; } } } if(flag) break; } ans[i] = {ln, rn - 1}; } int q; cin >> q; for (int i = 0; i < q; i++) { int a, b; cin >> a >> b; a--, b--; if(ans[a].ft <= b && b <= ans[a].sc) 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...