답안 #684315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684315 2023-01-20T21:45:15 Z stevancv Long Mansion (JOI17_long_mansion) C++14
25 / 100
3000 ms 52268 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];
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++) {
        int sz; cin >> sz;
        b[i].resize(sz);
        for (int j = 0; j < sz; j++) cin >> b[i][j];
    }
    for (int i = 1; i < n; i++) {
        for (int j : b[i]) lst[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 : b[i]) lst[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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12244 KB Output is correct
2 Correct 10 ms 12348 KB Output is correct
3 Correct 18 ms 12372 KB Output is correct
4 Correct 9 ms 12216 KB Output is correct
5 Correct 8 ms 12192 KB Output is correct
6 Correct 9 ms 12244 KB Output is correct
7 Correct 9 ms 12216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12244 KB Output is correct
2 Correct 10 ms 12348 KB Output is correct
3 Correct 18 ms 12372 KB Output is correct
4 Correct 9 ms 12216 KB Output is correct
5 Correct 8 ms 12192 KB Output is correct
6 Correct 9 ms 12244 KB Output is correct
7 Correct 9 ms 12216 KB Output is correct
8 Correct 101 ms 18120 KB Output is correct
9 Correct 99 ms 18012 KB Output is correct
10 Correct 102 ms 18396 KB Output is correct
11 Correct 113 ms 18824 KB Output is correct
12 Correct 90 ms 17692 KB Output is correct
13 Correct 97 ms 18352 KB Output is correct
14 Correct 105 ms 18272 KB Output is correct
15 Correct 98 ms 18252 KB Output is correct
16 Correct 94 ms 18032 KB Output is correct
17 Correct 96 ms 18252 KB Output is correct
18 Correct 98 ms 18296 KB Output is correct
19 Correct 98 ms 18340 KB Output is correct
20 Correct 95 ms 18284 KB Output is correct
21 Correct 95 ms 18096 KB Output is correct
22 Correct 94 ms 18088 KB Output is correct
23 Correct 102 ms 17992 KB Output is correct
24 Correct 96 ms 17976 KB Output is correct
25 Correct 99 ms 17996 KB Output is correct
26 Correct 96 ms 18060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 758 ms 19192 KB Output is correct
2 Correct 1462 ms 26480 KB Output is correct
3 Correct 2848 ms 26456 KB Output is correct
4 Correct 935 ms 26548 KB Output is correct
5 Correct 1072 ms 26532 KB Output is correct
6 Correct 2967 ms 25764 KB Output is correct
7 Correct 128 ms 25580 KB Output is correct
8 Correct 127 ms 25496 KB Output is correct
9 Correct 133 ms 25684 KB Output is correct
10 Correct 130 ms 25652 KB Output is correct
11 Correct 132 ms 25544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12244 KB Output is correct
2 Correct 10 ms 12348 KB Output is correct
3 Correct 18 ms 12372 KB Output is correct
4 Correct 9 ms 12216 KB Output is correct
5 Correct 8 ms 12192 KB Output is correct
6 Correct 9 ms 12244 KB Output is correct
7 Correct 9 ms 12216 KB Output is correct
8 Correct 101 ms 18120 KB Output is correct
9 Correct 99 ms 18012 KB Output is correct
10 Correct 102 ms 18396 KB Output is correct
11 Correct 113 ms 18824 KB Output is correct
12 Correct 90 ms 17692 KB Output is correct
13 Correct 97 ms 18352 KB Output is correct
14 Correct 105 ms 18272 KB Output is correct
15 Correct 98 ms 18252 KB Output is correct
16 Correct 94 ms 18032 KB Output is correct
17 Correct 96 ms 18252 KB Output is correct
18 Correct 98 ms 18296 KB Output is correct
19 Correct 98 ms 18340 KB Output is correct
20 Correct 95 ms 18284 KB Output is correct
21 Correct 95 ms 18096 KB Output is correct
22 Correct 94 ms 18088 KB Output is correct
23 Correct 102 ms 17992 KB Output is correct
24 Correct 96 ms 17976 KB Output is correct
25 Correct 99 ms 17996 KB Output is correct
26 Correct 96 ms 18060 KB Output is correct
27 Correct 758 ms 19192 KB Output is correct
28 Correct 1462 ms 26480 KB Output is correct
29 Correct 2848 ms 26456 KB Output is correct
30 Correct 935 ms 26548 KB Output is correct
31 Correct 1072 ms 26532 KB Output is correct
32 Correct 2967 ms 25764 KB Output is correct
33 Correct 128 ms 25580 KB Output is correct
34 Correct 127 ms 25496 KB Output is correct
35 Correct 133 ms 25684 KB Output is correct
36 Correct 130 ms 25652 KB Output is correct
37 Correct 132 ms 25544 KB Output is correct
38 Correct 223 ms 47060 KB Output is correct
39 Correct 229 ms 52268 KB Output is correct
40 Correct 200 ms 40496 KB Output is correct
41 Execution timed out 3045 ms 39032 KB Time limit exceeded
42 Halted 0 ms 0 KB -