# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
431235 | jamezzz | Long Mansion (JOI17_long_mansion) | C++17 | 481 ms | 42092 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;
typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements
#define DEBUG
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));
#define maxn 500005
int n,c[maxn],b[maxn],t,q,x,y;
bool have[maxn];
vector<int> a[maxn];
bool pos[5005][5005];
void small(){
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j)have[j]=false;
for(int j=0;j<b[i];++j)have[a[i][j]]=true;
int l=i,r=i;
while(true){
bool move=false;
if(l>1&&have[c[l]]){
--l;
for(int j=0;j<b[l];++j){
have[a[l][j]]=true;
}
move=true;
}
if(r<n&&have[c[r+1]]){
++r;
for(int j=0;j<b[r];++j){
have[a[r][j]]=true;
}
move=true;
}
if(!move)break;
}
for(int j=l;j<=r;++j)pos[i][j]=true;
}
sf("%d",&q);
for(int i=0;i<q;++i){
sf("%d%d",&x,&y);
if(pos[x][y])pf("YES\n");
else pf("NO\n");
}
}
int main(){
sf("%d",&n);
for(int i=2;i<=n;++i)sf("%d",&c[i]);
for(int i=1;i<=n;++i){
sf("%d",&b[i]);
for(int j=0;j<b[i];++j){
sf("%d",&t);
a[i].pb(t);
}
}
if(n<=5000)small();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |