Submission #516188

# Submission time Handle Problem Language Result Execution time Memory
516188 2022-01-20T15:04:05 Z K4YAN Long Mansion (JOI17_long_mansion) C++17
25 / 100
3000 ms 30464 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 int mxn = 5e5 + 32;
int n, t, k, q;
int c[mxn], cnt[mxn];
pii ans[mxn];
vector<int> 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) {
                break;
            }
            if(cnt[c[pr - 1]] > 0) {
                for(auto u : keys[pr]) cnt[u]++;
                pr++;
            } 
        }
        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 < 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) {
                break;
            }
            if(cnt[c[pl]] > 0) {
                for(auto u : keys[pl]) cnt[u]++;
                pl--;
            }
        }
        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 = pl + 1; i < r; i++) {
        for(auto u : keys[i]) cnt[u]--;
    }
    return;

}

void solve(int l, int r) {

    if(r - l <= 0) return;
    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 12204 KB Output is correct
3 Correct 10 ms 12324 KB Output is correct
4 Correct 9 ms 12236 KB Output is correct
5 Correct 8 ms 12236 KB Output is correct
6 Correct 8 ms 12236 KB Output is correct
7 Correct 8 ms 12204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12236 KB Output is correct
2 Correct 11 ms 12204 KB Output is correct
3 Correct 10 ms 12324 KB Output is correct
4 Correct 9 ms 12236 KB Output is correct
5 Correct 8 ms 12236 KB Output is correct
6 Correct 8 ms 12236 KB Output is correct
7 Correct 8 ms 12204 KB Output is correct
8 Correct 97 ms 14452 KB Output is correct
9 Correct 101 ms 14296 KB Output is correct
10 Correct 107 ms 14448 KB Output is correct
11 Correct 103 ms 14620 KB Output is correct
12 Correct 85 ms 14404 KB Output is correct
13 Correct 90 ms 14764 KB Output is correct
14 Correct 103 ms 14916 KB Output is correct
15 Correct 99 ms 15080 KB Output is correct
16 Correct 102 ms 15276 KB Output is correct
17 Correct 104 ms 15012 KB Output is correct
18 Correct 96 ms 15008 KB Output is correct
19 Correct 123 ms 14988 KB Output is correct
20 Correct 113 ms 15140 KB Output is correct
21 Correct 96 ms 15224 KB Output is correct
22 Correct 106 ms 15100 KB Output is correct
23 Correct 101 ms 14840 KB Output is correct
24 Correct 98 ms 14916 KB Output is correct
25 Correct 93 ms 14836 KB Output is correct
26 Correct 98 ms 14840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 264 ms 20252 KB Output is correct
2 Correct 288 ms 20264 KB Output is correct
3 Correct 255 ms 20240 KB Output is correct
4 Correct 258 ms 20256 KB Output is correct
5 Correct 252 ms 20224 KB Output is correct
6 Correct 201 ms 19852 KB Output is correct
7 Correct 193 ms 19888 KB Output is correct
8 Correct 188 ms 19944 KB Output is correct
9 Correct 182 ms 20176 KB Output is correct
10 Correct 186 ms 20008 KB Output is correct
11 Correct 195 ms 19892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12236 KB Output is correct
2 Correct 11 ms 12204 KB Output is correct
3 Correct 10 ms 12324 KB Output is correct
4 Correct 9 ms 12236 KB Output is correct
5 Correct 8 ms 12236 KB Output is correct
6 Correct 8 ms 12236 KB Output is correct
7 Correct 8 ms 12204 KB Output is correct
8 Correct 97 ms 14452 KB Output is correct
9 Correct 101 ms 14296 KB Output is correct
10 Correct 107 ms 14448 KB Output is correct
11 Correct 103 ms 14620 KB Output is correct
12 Correct 85 ms 14404 KB Output is correct
13 Correct 90 ms 14764 KB Output is correct
14 Correct 103 ms 14916 KB Output is correct
15 Correct 99 ms 15080 KB Output is correct
16 Correct 102 ms 15276 KB Output is correct
17 Correct 104 ms 15012 KB Output is correct
18 Correct 96 ms 15008 KB Output is correct
19 Correct 123 ms 14988 KB Output is correct
20 Correct 113 ms 15140 KB Output is correct
21 Correct 96 ms 15224 KB Output is correct
22 Correct 106 ms 15100 KB Output is correct
23 Correct 101 ms 14840 KB Output is correct
24 Correct 98 ms 14916 KB Output is correct
25 Correct 93 ms 14836 KB Output is correct
26 Correct 98 ms 14840 KB Output is correct
27 Correct 264 ms 20252 KB Output is correct
28 Correct 288 ms 20264 KB Output is correct
29 Correct 255 ms 20240 KB Output is correct
30 Correct 258 ms 20256 KB Output is correct
31 Correct 252 ms 20224 KB Output is correct
32 Correct 201 ms 19852 KB Output is correct
33 Correct 193 ms 19888 KB Output is correct
34 Correct 188 ms 19944 KB Output is correct
35 Correct 182 ms 20176 KB Output is correct
36 Correct 186 ms 20008 KB Output is correct
37 Correct 195 ms 19892 KB Output is correct
38 Execution timed out 3053 ms 30464 KB Time limit exceeded
39 Halted 0 ms 0 KB -