Submission #241678

# Submission time Handle Problem Language Result Execution time Memory
241678 2020-06-25T08:51:58 Z osaaateiasavtnl Long Mansion (JOI17_long_mansion) C++17
0 / 100
214 ms 26872 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 1 << 20;
int last[N]; 

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif


    int n;
    cin >> n;

    vector <int> c(n-1);
    for (int i = 0; i < n - 1; ++i)
        cin >> c[i];

    vector <vector <int> > a(n);
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        a[i].resize(k);
        for (int j = 0; j < k; ++j)
            cin >> a[i][j];
    }   

    vector <int> l(n), r(n);
    for (int i = 0; i < n; ++i) {
        l[i] = 0;
        r[i] = n - 1;
    }   

    vector <int> linkl(n), linkr(n);
    for (int i = 0; i < N; ++i)
        last[i] = -1;
    for (int i = 0; i < n - 1; ++i) {
        for (auto e : a[i])
            last[e] = i;
        linkl[i] = last[c[i]]+1;
    }   
    for (int i = 0; i < N; ++i)
        last[i] = n;
    for (int i = n - 1; i >= 0; --i) {
        if (i < n - 1) {
            linkr[i] = last[c[i]]-1;
        }
        for (auto e : a[i])
            last[e] = i;
    }

    for (int i = 0; i < n - 1; ++i) {
        //(i+1,linkr[i])
        for (int j = i; j <= linkr[i]; ++j) {
            if (linkl[j] <= i) {
                int sl = i+1;
                int sr = j;

                //cout << "find " << sl << ' ' << sr << endl;

                for (int k = sl; k <= sr; ++k) {
                    l[k] = max(l[k], sl);
                    r[k] = max(r[k], sr);
                }   
                
            }   
        }   
    }   

    /*
    for (int i = 0; i < n - 1; ++i) {
        cout << linkl[i] << ' ' << linkr[i] << endl;
    }
    */

    vector <int> t = {0, n - 1};
    for (int i : t) {
        l[i] = r[i] = i;
 
        set <int> cur;
        for (auto e : a[i])
            cur.insert(e);
 
        while (1) {
            if (l[i] && cur.find(c[l[i]-1]) != cur.end()) {
                --l[i];
                for (auto e : a[l[i]])
                    cur.insert(e);
            }   
            else if (r[i] < n - 1 && cur.find(c[r[i]]) != cur.end()) {
                ++r[i];
                for (auto e : a[r[i]])
                    cur.insert(e);
            }   
            else {
                break;
            }   
        }   
    }  

    /*
    cout << "seg : " << endl;
    for (int i = 0; i < n; ++i) 
        cout << l[i] << ' ' << r[i] << endl;
    */

    int q;
    cin >> q;
    while (q--) {
        int i, j;
        cin >> i >> j;
        --i; --j;
        if (l[i] <= j && j <= r[i]) {
            cout << "YES" << endl;
        }   
        else {
            cout << "NO" << endl;
        }   
    }   
}
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 8704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 8704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 26872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 8704 KB Output isn't correct
2 Halted 0 ms 0 KB -