| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1256327 | hainam2k9 | Long Mansion (JOI17_long_mansion) | C++20 | 152 ms | 59080 KiB | 
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 5e5+5;
const string NAME = "";
int n,q,c[MAXN],last[MAXN],l[MAXN],r[MAXN];
pair<int,int> p[MAXN];
vector<int> v[MAXN];
bool vis[MAXN];
bool checkleft(int L, int R){
    if(L>1&&r[L-1]>=L&&r[L-1]<=R) return 1;
    return 0;
}
bool checkright(int L, int R){
    if(R<n&&l[R+1]>=L&&l[R+1]<=R) return 1;
    return 0;
}
void calc(int i){
    if(vis[i]) return;
    vis[i]=1;
    while(1){
        if(checkleft(p[i].fi,p[i].se)){
            int nxt=p[i].fi-1;
            calc(nxt);
            p[i].fi=min(p[i].fi,p[nxt].fi),
            p[i].se=max(p[i].se,p[nxt].se);
        }else if(checkright(p[i].fi,p[i].se)){
            int nxt=p[i].se+1;
            calc(nxt);
            p[i].fi=min(p[i].fi,p[nxt].fi),
            p[i].se=max(p[i].se,p[nxt].se);
        }else break;
    }
}
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n;
    for(int i = 1; i<n; ++i)
        cin >> c[i];
    memset(last,0x3f,sizeof(last));
    for(int i = 1; i<=n; ++i){
        if(i>1) l[i]=min(i,last[c[i-1]]);
        int sz;
        cin >> sz;
        v[i].resize(sz);
        for(int j = 0; j<sz; ++j)
            cin >> v[i][j], last[v[i][j]]=i;
    }
    memset(last,0,sizeof(last));
    for(int i = n; i>0; --i){
        if(i<n) r[i]=max(i,last[c[i]]);
        for(int j = 0; j<sz(v[i]); ++j)
            last[v[i][j]]=i;
    }
    l[1]=1, r[n]=n;
    for(int i = 1; i<=n; ++i)
        p[i]={i,i};
    for(int i = 1; i<=n; ++i)
        calc(i);
    cin >> q;
    while(q--){
        int x,y;
        cin >> x >> y;
        if(y>=p[x].fi&&y<=p[x].se) cout << "YES\n";
        else cout << "NO\n";
    }
}
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... | ||||
