답안 #868372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868372 2023-10-31T08:57:21 Z azberjibiou Long Mansion (JOI17_long_mansion) C++17
5 / 100
123 ms 36688 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=300030;
const int mxM=500004;
const int MOD=998244353;
const ll INF=8e18;
int N, Q;
vector <int> key[mxN];
vector <int> kpos[mxN];
int C[mxN];
int l[mxN], r[mxN];
int kp[mxN];
pii qry[mxN];
pii rng[mxN];
void input(){
    cin >> N;
    for(int i=1;i<N;i++)    cin >> C[i];
    for(int i=1;i<=N;i++){
        int a;
        cin >> a;
        while(a--){
            int b;
            cin >> b;
            key[i].push_back(b);
        }
    }
    cin >> Q;
    for(int i=1;i<=Q;i++){
        cin >> qry[i].fi >> qry[i].se;
    }
}
void make_lr(){
    for(int i=1;i<=N;i++){
        for(int x : key[i]) kp[x]=i;
        if(i==N)    break;
        l[i]=kp[C[i]];
    }
    for(int i=1;i<=N;i++)   kp[i]=N+1;
    for(int i=N;i>=1;i--){
        for(int x : key[i]) kp[x]=i;
        if(i==1)    break;
        r[i-1]=kp[C[i-1]];
    }
}
void f(int now){
    int s=now, e=now;
    while(true){
        if(s!=1 && r[s-1]<=e){
            s--;
            s=min(s, rng[s].fi);
            e=max(e, rng[s].se);
            continue;
        }
        if(e!=N && l[e]>=s){
            e++;
            s=min(s, rng[e].fi);
            e=max(e, rng[e].se);
            continue;
        }
        break;
    }
    rng[now]=pii(s, e);
}
int main()
{
    gibon
    input();
    make_lr();
    for(int i=1;i<=N;i++)   rng[i]=pii(i, i);
    int M=sqrt(N);
    for(int i=0;i<M;i++){
        int s=N;
        while(s%M!=i)   s--;
        for(;s>=1;s-=M){
            f(s);
        }
    }
    for(int i=1;i<=Q;i++)
    {
        auto [a, b]=qry[i];
        if(b<rng[a].fi || b>rng[a].se)  cout << "NO\n";
        else    cout << "YES\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21848 KB Output is correct
2 Correct 6 ms 21852 KB Output is correct
3 Correct 6 ms 21972 KB Output is correct
4 Correct 5 ms 21852 KB Output is correct
5 Correct 6 ms 21852 KB Output is correct
6 Correct 6 ms 21724 KB Output is correct
7 Correct 5 ms 21852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21848 KB Output is correct
2 Correct 6 ms 21852 KB Output is correct
3 Correct 6 ms 21972 KB Output is correct
4 Correct 5 ms 21852 KB Output is correct
5 Correct 6 ms 21852 KB Output is correct
6 Correct 6 ms 21724 KB Output is correct
7 Correct 5 ms 21852 KB Output is correct
8 Incorrect 69 ms 27728 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 123 ms 36688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21848 KB Output is correct
2 Correct 6 ms 21852 KB Output is correct
3 Correct 6 ms 21972 KB Output is correct
4 Correct 5 ms 21852 KB Output is correct
5 Correct 6 ms 21852 KB Output is correct
6 Correct 6 ms 21724 KB Output is correct
7 Correct 5 ms 21852 KB Output is correct
8 Incorrect 69 ms 27728 KB Output isn't correct
9 Halted 0 ms 0 KB -