Submission #235199

#TimeUsernameProblemLanguageResultExecution timeMemory
235199Knps4422Long Mansion (JOI17_long_mansion)C++14
0 / 100
3036 ms30872 KiB
//#pragma optimization_level 3 //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include<bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset; */ #define fr first #define sc second #define vec vector #define pb push_back #define pii pair<int, int> #define forn(x,y) for(int x = 1 ; x <= y ; ++x) #define all(x) (x).begin(),(x).end() #define debug(x) cout <<"---"<<x<< ' '; #define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0); #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using namespace std; typedef unsigned long long ll; typedef unsigned int uint; typedef pair<ll,ll> pll; const int nmax = 500005; const ll linf = LLONG_MAX/2; const ll mod = 1e9+7; const int inf = 1e9+7; int n, q; ll key[nmax]; vec < int > ks[nmax], col[nmax]; int cl[nmax], cr[nmax], pl[nmax], pr[nmax], limitl[nmax], limitr[nmax]; int main(){ cin >> n; forn(i,n-1){ cin >> key[i]; } int s, asd; forn(i,n){ cin >> s; forn(ii,s){ cin >> asd; col[asd].pb(i); ks[i].pb(asd); } sort(all(ks[i])); } cr[0] = inf; cl[1] = -1; cr[n] = inf; cl[n+1] = -1; for(int i = 1; i <= n; i++){ cl[i+1] = -1; cr[i] = inf; for(int j : col[key[i]]){ if(j > i) cr[i] = min(cr[i],j); if(j < i+1) cl[i+1] = max(cl[i+1],j); } } for(int i = 1; i <= n; i++){ bool check = true; int j; for(j = cl[i] ; check && j < i && j != -1 ; j++){ if(cr[j] > i)check = false; } pl[i] = j - 1; } for(int i = 1; i <= n; i++){ bool check = true; int j; for(j = cr[i] ; check && j > i && j != inf ; j--){ if(cl[j] < i)check = false; } pr[i] = j + 1; } /*cout << "!!!!!\n"; forn(i,n){ cout << i << ' ' << cl[i] << ' ' << cr[i] << '\n'; } cout << "!!!!!\n"; forn(i,n){ cout << i << ' ' << pl[i] << ' ' << pr[i] << '\n'; } cout << "!!!!!\n"; forn(i,n){ cout << i << ' ' << } cout << "!!!!!\n";*/ cin >> q; while(q--){ int x, y; cin >> x >> y; if( x < y){ int p = x + 1; while(p <= n && pl[p] >= x - 1 )p++; p--; cout << ( p >= y ? "YES\n" : "NO\n"); }else{ int p = x - 1; while(p >= 0 && pr[p] <= x + 1)p--; p++; cout << ( p <= y ? "YES\n" : "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...