Submission #516159

# Submission time Handle Problem Language Result Execution time Memory
516159 2022-01-20T13:59:56 Z K4YAN Long Mansion (JOI17_long_mansion) C++17
25 / 100
3000 ms 33032 KB
//Be Name Khoda

#include<bits/stdc++.h>
#pragma GCC target ("avx2,tune=native")

using namespace std;

#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define plll pair<pll, ll>

const ll mxn = 5e5 + 16, INF = 1LL * 1e17 + 32;
ll n, t, k, q;
ll c[mxn], cnt[mxn];
pll ans[mxn];
vector<ll> keys[mxn];

void input() {

    cin >> n;
    for(int i = 1; i < n; i++) {
        cin >> c[i];
    }
    for(int i = 1; i <= n; i++) {
        cin >> k;
        for(int j = 0; j < k; j++) {
            cin >> q;
            keys[i].push_back(q);
        }
    } cin >> t;

}

inline void merge(int l, int r, int m) {

    bool mark[r - l + 5];
    int tmp[r - l + 5];
    int pr = m, pl = m - 1;
    memset(mark, 0, sizeof(mark));

    for(int i = m - 1; i > l - 1; i--) {
        for(auto u : keys[i]) cnt[u]++;
        while(pr < r) {
            if(cnt[c[pr - 1]] > 0) {
                for(auto u : keys[pr]) cnt[u]++;
                pr++;
            } 
            else break;
        }
        tmp[i - l] = pr;
        if(i > l) {
            if(cnt[c[i - 1]] > 0) mark[i - l] = 1;
        }
    }
    for(int i = l; i < m; i++) {
        if(mark[i - l]) continue;
        if(ans[i].second >= m) {
            ans[i].second = tmp[i - l];
        }
        for(int j = i + 1; j < m; j++) {
            if(!mark[j - l]) break;
            if(ans[j].second < m) continue;
            ans[j].first = i, ans[j].second = tmp[i - l];
        }
    }

    for(int i = l; i < m; i++) {
        for(auto u : keys[i]) cnt[u]--;
    }
    for(int i = m; i < pr; i++) {
        for(auto u : keys[i]) cnt[u]--;
    }
    for(int i = m; i < r; i++) {
        for(auto u : keys[i]) cnt[u]++;
        while(pl > l - 1) {
            if(cnt[c[pl]] > 0) {
                for(auto u : keys[pl]) cnt[u]++;
                pl--;
            }
            else break;
        }
        tmp[i - l] = pl + 1;
        if(i < r - 1) {
            if(cnt[c[i]] > 0) mark[i - l] = 1;
        }
    }
    for(int i = r - 1; i > m - 1; i--) {
        if(mark[i - l]) continue;
        if(ans[i].first <= m) {
            ans[i].first = tmp[i - l];
        }
        for(int j = i - 1; j > m - 1; j--) {
            if(!mark[j - l]) continue;
            if(ans[j].first > m) continue;
            ans[j].first = tmp[i - l], ans[j].second = i + 1;
        }
    }
    for(int i = m; i < r; i++) {
        for(auto u : keys[i]) cnt[u]--;
    }
    for(int i = m - 1; i > pl; i--) {
        for(auto u : keys[i]) cnt[u]--;
    }
    return;

}

void solve(int l, int r) {

    if(r - l == 1) {
        ans[l] = make_pair(l, r);
        return;
    }
    int m = (l + r) >> 1;
    solve(l, m); solve(m, r);
    merge(l, r, m);
    return;

}

int main() {

    ios::sync_with_stdio(false); cin.tie(NULL);

    input(), solve(1, n + 1);
    for(int i = 0; i < t; i++) {
        int x, y;
        cin >> x >> y;
        if(y < ans[x].first || ans[x].second <= y) {
            cout << "NO\n";
            continue;
        }
        cout << "YES\n";
    }
    return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12236 KB Output is correct
2 Correct 11 ms 12332 KB Output is correct
3 Correct 10 ms 12492 KB Output is correct
4 Correct 9 ms 12204 KB Output is correct
5 Correct 9 ms 12280 KB Output is correct
6 Correct 9 ms 12236 KB Output is correct
7 Correct 8 ms 12236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12236 KB Output is correct
2 Correct 11 ms 12332 KB Output is correct
3 Correct 10 ms 12492 KB Output is correct
4 Correct 9 ms 12204 KB Output is correct
5 Correct 9 ms 12280 KB Output is correct
6 Correct 9 ms 12236 KB Output is correct
7 Correct 8 ms 12236 KB Output is correct
8 Correct 96 ms 13924 KB Output is correct
9 Correct 87 ms 13908 KB Output is correct
10 Correct 93 ms 14068 KB Output is correct
11 Correct 86 ms 14276 KB Output is correct
12 Correct 80 ms 14112 KB Output is correct
13 Correct 87 ms 14244 KB Output is correct
14 Correct 82 ms 14084 KB Output is correct
15 Correct 85 ms 14212 KB Output is correct
16 Correct 81 ms 14404 KB Output is correct
17 Correct 85 ms 14280 KB Output is correct
18 Correct 82 ms 14148 KB Output is correct
19 Correct 82 ms 14124 KB Output is correct
20 Correct 95 ms 14332 KB Output is correct
21 Correct 82 ms 14372 KB Output is correct
22 Correct 84 ms 14184 KB Output is correct
23 Correct 86 ms 14020 KB Output is correct
24 Correct 86 ms 14020 KB Output is correct
25 Correct 85 ms 13960 KB Output is correct
26 Correct 85 ms 14004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 259 ms 22636 KB Output is correct
2 Correct 260 ms 22660 KB Output is correct
3 Correct 244 ms 22492 KB Output is correct
4 Correct 255 ms 22636 KB Output is correct
5 Correct 252 ms 22696 KB Output is correct
6 Correct 184 ms 20296 KB Output is correct
7 Correct 186 ms 20440 KB Output is correct
8 Correct 183 ms 20384 KB Output is correct
9 Correct 193 ms 20220 KB Output is correct
10 Correct 177 ms 20236 KB Output is correct
11 Correct 181 ms 20292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12236 KB Output is correct
2 Correct 11 ms 12332 KB Output is correct
3 Correct 10 ms 12492 KB Output is correct
4 Correct 9 ms 12204 KB Output is correct
5 Correct 9 ms 12280 KB Output is correct
6 Correct 9 ms 12236 KB Output is correct
7 Correct 8 ms 12236 KB Output is correct
8 Correct 96 ms 13924 KB Output is correct
9 Correct 87 ms 13908 KB Output is correct
10 Correct 93 ms 14068 KB Output is correct
11 Correct 86 ms 14276 KB Output is correct
12 Correct 80 ms 14112 KB Output is correct
13 Correct 87 ms 14244 KB Output is correct
14 Correct 82 ms 14084 KB Output is correct
15 Correct 85 ms 14212 KB Output is correct
16 Correct 81 ms 14404 KB Output is correct
17 Correct 85 ms 14280 KB Output is correct
18 Correct 82 ms 14148 KB Output is correct
19 Correct 82 ms 14124 KB Output is correct
20 Correct 95 ms 14332 KB Output is correct
21 Correct 82 ms 14372 KB Output is correct
22 Correct 84 ms 14184 KB Output is correct
23 Correct 86 ms 14020 KB Output is correct
24 Correct 86 ms 14020 KB Output is correct
25 Correct 85 ms 13960 KB Output is correct
26 Correct 85 ms 14004 KB Output is correct
27 Correct 259 ms 22636 KB Output is correct
28 Correct 260 ms 22660 KB Output is correct
29 Correct 244 ms 22492 KB Output is correct
30 Correct 255 ms 22636 KB Output is correct
31 Correct 252 ms 22696 KB Output is correct
32 Correct 184 ms 20296 KB Output is correct
33 Correct 186 ms 20440 KB Output is correct
34 Correct 183 ms 20384 KB Output is correct
35 Correct 193 ms 20220 KB Output is correct
36 Correct 177 ms 20236 KB Output is correct
37 Correct 181 ms 20292 KB Output is correct
38 Execution timed out 3075 ms 33032 KB Time limit exceeded
39 Halted 0 ms 0 KB -