Submission #684331

# Submission time Handle Problem Language Result Execution time Memory
684331 2023-01-20T22:21:21 Z stevancv Long Mansion (JOI17_long_mansion) C++14
10 / 100
3000 ms 19788 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 5e5 + 2;
const int inf = 1e9;
int c[N], le[N], ri[N], l[N], r[N], lst[N], sz[N];
vector<int> b[N];
bool Between(int L, int R, int x) {
    return L <= x && x <= R;
}
bool Can(int L, int R, int x) {
    return Between(L, R, le[x]) || Between(L, R, ri[x]);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    for (int i = 1; i < n; i++) cin >> c[i];
    for (int i = 1; i <= n; i++) {
        cin >> sz[i];
        b[i].resize(sz[i]);
        for (int j = 0; j < sz[i]; j++) cin >> b[i][j];
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < sz[i]; j++) lst[b[i][j]] = i;
        le[i] = lst[c[i]];
    }
    for (int i = 1; i <= n; i++) lst[i] = 0;
    for (int i = n; i > 1; i--) {
        for (int j = 0; j < sz[i]; j++) lst[b[i][j]] = i;
        ri[i - 1] = lst[c[i - 1]];
    }
    for (int i = 1; i <= n; i++) {
        l[i] = r[i] = i;
        while (1) {
            if (l[i] > 1 && Can(l[i], r[i], l[i] - 1)) {
                l[i] = l[l[i] - 1];
                smax(r[i], r[l[i]]);
            }
            else if (r[i] < n && Can(l[i], r[i], r[i])) r[i]++;
            else break;
        }
    }
    int q; cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y;
        if (Between(l[x], r[x], y)) cout << "YES" << en;
        else cout << "NO" << en;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12244 KB Output is correct
2 Correct 10 ms 12244 KB Output is correct
3 Correct 22 ms 12380 KB Output is correct
4 Correct 8 ms 12244 KB Output is correct
5 Correct 10 ms 12244 KB Output is correct
6 Correct 8 ms 12244 KB Output is correct
7 Correct 8 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12244 KB Output is correct
2 Correct 10 ms 12244 KB Output is correct
3 Correct 22 ms 12380 KB Output is correct
4 Correct 8 ms 12244 KB Output is correct
5 Correct 10 ms 12244 KB Output is correct
6 Correct 8 ms 12244 KB Output is correct
7 Correct 8 ms 12244 KB Output is correct
8 Correct 95 ms 13756 KB Output is correct
9 Correct 93 ms 13632 KB Output is correct
10 Correct 100 ms 13932 KB Output is correct
11 Correct 101 ms 14156 KB Output is correct
12 Correct 89 ms 13904 KB Output is correct
13 Correct 117 ms 13892 KB Output is correct
14 Correct 91 ms 13868 KB Output is correct
15 Correct 97 ms 14028 KB Output is correct
16 Correct 92 ms 14156 KB Output is correct
17 Correct 105 ms 13904 KB Output is correct
18 Correct 92 ms 13920 KB Output is correct
19 Correct 90 ms 13900 KB Output is correct
20 Correct 91 ms 14044 KB Output is correct
21 Correct 111 ms 14160 KB Output is correct
22 Correct 91 ms 13980 KB Output is correct
23 Correct 95 ms 13720 KB Output is correct
24 Correct 103 ms 13856 KB Output is correct
25 Correct 97 ms 13868 KB Output is correct
26 Correct 95 ms 13776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 746 ms 19708 KB Output is correct
2 Correct 1484 ms 19684 KB Output is correct
3 Correct 2932 ms 19652 KB Output is correct
4 Correct 999 ms 19788 KB Output is correct
5 Correct 1099 ms 19756 KB Output is correct
6 Execution timed out 3067 ms 19752 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12244 KB Output is correct
2 Correct 10 ms 12244 KB Output is correct
3 Correct 22 ms 12380 KB Output is correct
4 Correct 8 ms 12244 KB Output is correct
5 Correct 10 ms 12244 KB Output is correct
6 Correct 8 ms 12244 KB Output is correct
7 Correct 8 ms 12244 KB Output is correct
8 Correct 95 ms 13756 KB Output is correct
9 Correct 93 ms 13632 KB Output is correct
10 Correct 100 ms 13932 KB Output is correct
11 Correct 101 ms 14156 KB Output is correct
12 Correct 89 ms 13904 KB Output is correct
13 Correct 117 ms 13892 KB Output is correct
14 Correct 91 ms 13868 KB Output is correct
15 Correct 97 ms 14028 KB Output is correct
16 Correct 92 ms 14156 KB Output is correct
17 Correct 105 ms 13904 KB Output is correct
18 Correct 92 ms 13920 KB Output is correct
19 Correct 90 ms 13900 KB Output is correct
20 Correct 91 ms 14044 KB Output is correct
21 Correct 111 ms 14160 KB Output is correct
22 Correct 91 ms 13980 KB Output is correct
23 Correct 95 ms 13720 KB Output is correct
24 Correct 103 ms 13856 KB Output is correct
25 Correct 97 ms 13868 KB Output is correct
26 Correct 95 ms 13776 KB Output is correct
27 Correct 746 ms 19708 KB Output is correct
28 Correct 1484 ms 19684 KB Output is correct
29 Correct 2932 ms 19652 KB Output is correct
30 Correct 999 ms 19788 KB Output is correct
31 Correct 1099 ms 19756 KB Output is correct
32 Execution timed out 3067 ms 19752 KB Time limit exceeded
33 Halted 0 ms 0 KB -