Submission #241681

# Submission time Handle Problem Language Result Execution time Memory
241681 2020-06-25T09:07:55 Z osaaateiasavtnl Long Mansion (JOI17_long_mansion) C++17
25 / 100
3000 ms 46456 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+1) {
                int sl = i+1;
                int sr = j;
                for (int k = sl; k <= sr; ++k) {
                    l[k] = max(l[k], sl);
                    r[k] = min(r[k], sr);
                }                   
            }   
        }   
    }   

    for (int i = 0; i < n; ++i) {
        if (linkl[i] == 0) {
            for (int j = 0; j <= i; ++j)
                r[j] = min(r[j], i);
        }   
    }

    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 Correct 12 ms 8832 KB Output is correct
2 Correct 13 ms 8960 KB Output is correct
3 Correct 13 ms 9088 KB Output is correct
4 Correct 13 ms 8832 KB Output is correct
5 Correct 11 ms 8832 KB Output is correct
6 Correct 11 ms 8832 KB Output is correct
7 Correct 249 ms 8832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8832 KB Output is correct
2 Correct 13 ms 8960 KB Output is correct
3 Correct 13 ms 9088 KB Output is correct
4 Correct 13 ms 8832 KB Output is correct
5 Correct 11 ms 8832 KB Output is correct
6 Correct 11 ms 8832 KB Output is correct
7 Correct 249 ms 8832 KB Output is correct
8 Correct 125 ms 10364 KB Output is correct
9 Correct 122 ms 10360 KB Output is correct
10 Correct 126 ms 10616 KB Output is correct
11 Correct 134 ms 10872 KB Output is correct
12 Correct 114 ms 10468 KB Output is correct
13 Correct 120 ms 10616 KB Output is correct
14 Correct 131 ms 10564 KB Output is correct
15 Correct 122 ms 10744 KB Output is correct
16 Correct 124 ms 10872 KB Output is correct
17 Correct 127 ms 10616 KB Output is correct
18 Correct 121 ms 10744 KB Output is correct
19 Correct 118 ms 10616 KB Output is correct
20 Correct 124 ms 10744 KB Output is correct
21 Correct 123 ms 10848 KB Output is correct
22 Correct 120 ms 10580 KB Output is correct
23 Correct 366 ms 10492 KB Output is correct
24 Correct 364 ms 10492 KB Output is correct
25 Correct 362 ms 10488 KB Output is correct
26 Correct 465 ms 10360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 233 ms 21220 KB Output is correct
2 Correct 222 ms 21368 KB Output is correct
3 Correct 227 ms 21112 KB Output is correct
4 Correct 212 ms 21368 KB Output is correct
5 Correct 210 ms 21244 KB Output is correct
6 Correct 186 ms 20216 KB Output is correct
7 Correct 176 ms 20472 KB Output is correct
8 Correct 189 ms 20344 KB Output is correct
9 Correct 184 ms 20344 KB Output is correct
10 Correct 201 ms 20472 KB Output is correct
11 Correct 194 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8832 KB Output is correct
2 Correct 13 ms 8960 KB Output is correct
3 Correct 13 ms 9088 KB Output is correct
4 Correct 13 ms 8832 KB Output is correct
5 Correct 11 ms 8832 KB Output is correct
6 Correct 11 ms 8832 KB Output is correct
7 Correct 249 ms 8832 KB Output is correct
8 Correct 125 ms 10364 KB Output is correct
9 Correct 122 ms 10360 KB Output is correct
10 Correct 126 ms 10616 KB Output is correct
11 Correct 134 ms 10872 KB Output is correct
12 Correct 114 ms 10468 KB Output is correct
13 Correct 120 ms 10616 KB Output is correct
14 Correct 131 ms 10564 KB Output is correct
15 Correct 122 ms 10744 KB Output is correct
16 Correct 124 ms 10872 KB Output is correct
17 Correct 127 ms 10616 KB Output is correct
18 Correct 121 ms 10744 KB Output is correct
19 Correct 118 ms 10616 KB Output is correct
20 Correct 124 ms 10744 KB Output is correct
21 Correct 123 ms 10848 KB Output is correct
22 Correct 120 ms 10580 KB Output is correct
23 Correct 366 ms 10492 KB Output is correct
24 Correct 364 ms 10492 KB Output is correct
25 Correct 362 ms 10488 KB Output is correct
26 Correct 465 ms 10360 KB Output is correct
27 Correct 233 ms 21220 KB Output is correct
28 Correct 222 ms 21368 KB Output is correct
29 Correct 227 ms 21112 KB Output is correct
30 Correct 212 ms 21368 KB Output is correct
31 Correct 210 ms 21244 KB Output is correct
32 Correct 186 ms 20216 KB Output is correct
33 Correct 176 ms 20472 KB Output is correct
34 Correct 189 ms 20344 KB Output is correct
35 Correct 184 ms 20344 KB Output is correct
36 Correct 201 ms 20472 KB Output is correct
37 Correct 194 ms 20216 KB Output is correct
38 Execution timed out 3088 ms 46456 KB Time limit exceeded
39 Halted 0 ms 0 KB -