답안 #1081932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081932 2024-08-30T13:01:05 Z daoquanglinh2007 Long Mansion (JOI17_long_mansion) C++
100 / 100
179 ms 43088 KB
#include <bits/stdc++.h>
using namespace std;
 
const int NM = 5e5;
 
int N, Q, C[NM+5], B[NM+5], pre[NM+5], nxt[NM+5], lst[NM+5];
vector <int> arr[NM+5];
int l[NM+5], r[NM+5];
 
void solve(int u){
    int curl = u, curr = u;
    while (true){
        if (curl > 1 && nxt[curl] <= curr){
            curl--;
            if (r[curl] >= u){
                l[u] = l[curl];
                r[u] = r[curl];
                return;
            }
        }
        else if (curr < N && pre[curr] >= curl){
            curr++;
        }
        else break;
    }
    l[u] = curl, r[u] = curr;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    cin >> N;
    for (int i = 1; i < N; i++) cin >> C[i];
    for (int i = 1; i <= N; i++){
        cin >> B[i];
        arr[i].resize(B[i]);
        for (int j = 0; j < B[i]; j++) cin >> arr[i][j];
    }
    for (int i = 1; i < N; i++){
        for (int x : arr[i]) lst[x] = i;
        pre[i] = lst[C[i]];
    }
    for (int i = 1; i <= N; i++) lst[i] = N+1;
    for (int i = N; i > 1; i--){
        for (int x : arr[i]) lst[x] = i;
        nxt[i] = lst[C[i-1]];
    }
    for (int i = 1; i <= N; i++) solve(i);
 
    cin >> Q;
    while (Q--){
        int x, y; cin >> x >> y;
        if (l[x] <= y && r[x] >= y){
            cout << "YES\n";
            continue;
        }
        cout << "NO\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23132 KB Output is correct
2 Correct 4 ms 23128 KB Output is correct
3 Correct 5 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 4 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23132 KB Output is correct
2 Correct 4 ms 23128 KB Output is correct
3 Correct 5 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 4 ms 16988 KB Output is correct
8 Correct 65 ms 18516 KB Output is correct
9 Correct 61 ms 18352 KB Output is correct
10 Correct 59 ms 22740 KB Output is correct
11 Correct 60 ms 22864 KB Output is correct
12 Correct 53 ms 22608 KB Output is correct
13 Correct 66 ms 22608 KB Output is correct
14 Correct 56 ms 18704 KB Output is correct
15 Correct 60 ms 18768 KB Output is correct
16 Correct 60 ms 16980 KB Output is correct
17 Correct 57 ms 24656 KB Output is correct
18 Correct 57 ms 22740 KB Output is correct
19 Correct 58 ms 24856 KB Output is correct
20 Correct 62 ms 22864 KB Output is correct
21 Correct 55 ms 24912 KB Output is correct
22 Correct 58 ms 22840 KB Output is correct
23 Correct 59 ms 18480 KB Output is correct
24 Correct 64 ms 22608 KB Output is correct
25 Correct 65 ms 24596 KB Output is correct
26 Correct 67 ms 22528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 28340 KB Output is correct
2 Correct 115 ms 26808 KB Output is correct
3 Correct 102 ms 28500 KB Output is correct
4 Correct 103 ms 26836 KB Output is correct
5 Correct 112 ms 28332 KB Output is correct
6 Correct 108 ms 28392 KB Output is correct
7 Correct 87 ms 26964 KB Output is correct
8 Correct 79 ms 26916 KB Output is correct
9 Correct 102 ms 25428 KB Output is correct
10 Correct 88 ms 27048 KB Output is correct
11 Correct 138 ms 28752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23132 KB Output is correct
2 Correct 4 ms 23128 KB Output is correct
3 Correct 5 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 4 ms 16988 KB Output is correct
8 Correct 65 ms 18516 KB Output is correct
9 Correct 61 ms 18352 KB Output is correct
10 Correct 59 ms 22740 KB Output is correct
11 Correct 60 ms 22864 KB Output is correct
12 Correct 53 ms 22608 KB Output is correct
13 Correct 66 ms 22608 KB Output is correct
14 Correct 56 ms 18704 KB Output is correct
15 Correct 60 ms 18768 KB Output is correct
16 Correct 60 ms 16980 KB Output is correct
17 Correct 57 ms 24656 KB Output is correct
18 Correct 57 ms 22740 KB Output is correct
19 Correct 58 ms 24856 KB Output is correct
20 Correct 62 ms 22864 KB Output is correct
21 Correct 55 ms 24912 KB Output is correct
22 Correct 58 ms 22840 KB Output is correct
23 Correct 59 ms 18480 KB Output is correct
24 Correct 64 ms 22608 KB Output is correct
25 Correct 65 ms 24596 KB Output is correct
26 Correct 67 ms 22528 KB Output is correct
27 Correct 108 ms 28340 KB Output is correct
28 Correct 115 ms 26808 KB Output is correct
29 Correct 102 ms 28500 KB Output is correct
30 Correct 103 ms 26836 KB Output is correct
31 Correct 112 ms 28332 KB Output is correct
32 Correct 108 ms 28392 KB Output is correct
33 Correct 87 ms 26964 KB Output is correct
34 Correct 79 ms 26916 KB Output is correct
35 Correct 102 ms 25428 KB Output is correct
36 Correct 88 ms 27048 KB Output is correct
37 Correct 138 ms 28752 KB Output is correct
38 Correct 179 ms 38632 KB Output is correct
39 Correct 172 ms 42836 KB Output is correct
40 Correct 136 ms 35156 KB Output is correct
41 Correct 173 ms 43088 KB Output is correct
42 Correct 83 ms 26704 KB Output is correct
43 Correct 83 ms 28496 KB Output is correct
44 Correct 112 ms 30800 KB Output is correct
45 Correct 115 ms 30752 KB Output is correct
46 Correct 117 ms 30588 KB Output is correct
47 Correct 105 ms 28496 KB Output is correct
48 Correct 82 ms 28500 KB Output is correct
49 Correct 121 ms 30804 KB Output is correct
50 Correct 111 ms 31968 KB Output is correct
51 Correct 117 ms 31924 KB Output is correct
52 Correct 111 ms 30556 KB Output is correct
53 Correct 139 ms 34640 KB Output is correct
54 Correct 145 ms 38992 KB Output is correct
55 Correct 134 ms 35152 KB Output is correct