답안 #1081931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081931 2024-08-30T13:00:35 Z daoquanglinh2007 Long Mansion (JOI17_long_mansion) C++17
100 / 100
197 ms 54608 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 4 ms 25176 KB Output is correct
2 Correct 4 ms 25432 KB Output is correct
3 Correct 5 ms 19288 KB Output is correct
4 Correct 5 ms 25120 KB Output is correct
5 Correct 4 ms 25080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 25176 KB Output is correct
2 Correct 4 ms 25432 KB Output is correct
3 Correct 5 ms 19288 KB Output is correct
4 Correct 5 ms 25120 KB Output is correct
5 Correct 4 ms 25080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 19036 KB Output is correct
8 Correct 60 ms 24840 KB Output is correct
9 Correct 59 ms 30800 KB Output is correct
10 Correct 65 ms 31312 KB Output is correct
11 Correct 64 ms 31572 KB Output is correct
12 Correct 57 ms 30464 KB Output is correct
13 Correct 59 ms 31056 KB Output is correct
14 Correct 60 ms 31216 KB Output is correct
15 Correct 64 ms 25428 KB Output is correct
16 Correct 54 ms 30804 KB Output is correct
17 Correct 71 ms 31056 KB Output is correct
18 Correct 58 ms 29172 KB Output is correct
19 Correct 80 ms 31056 KB Output is correct
20 Correct 65 ms 29012 KB Output is correct
21 Correct 55 ms 29012 KB Output is correct
22 Correct 55 ms 31056 KB Output is correct
23 Correct 64 ms 30804 KB Output is correct
24 Correct 61 ms 24660 KB Output is correct
25 Correct 59 ms 26704 KB Output is correct
26 Correct 57 ms 24656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 37204 KB Output is correct
2 Correct 97 ms 37168 KB Output is correct
3 Correct 96 ms 37076 KB Output is correct
4 Correct 116 ms 35692 KB Output is correct
5 Correct 98 ms 37200 KB Output is correct
6 Correct 89 ms 36516 KB Output is correct
7 Correct 80 ms 36432 KB Output is correct
8 Correct 82 ms 36184 KB Output is correct
9 Correct 78 ms 36180 KB Output is correct
10 Correct 82 ms 36188 KB Output is correct
11 Correct 77 ms 36364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 25176 KB Output is correct
2 Correct 4 ms 25432 KB Output is correct
3 Correct 5 ms 19288 KB Output is correct
4 Correct 5 ms 25120 KB Output is correct
5 Correct 4 ms 25080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 19036 KB Output is correct
8 Correct 60 ms 24840 KB Output is correct
9 Correct 59 ms 30800 KB Output is correct
10 Correct 65 ms 31312 KB Output is correct
11 Correct 64 ms 31572 KB Output is correct
12 Correct 57 ms 30464 KB Output is correct
13 Correct 59 ms 31056 KB Output is correct
14 Correct 60 ms 31216 KB Output is correct
15 Correct 64 ms 25428 KB Output is correct
16 Correct 54 ms 30804 KB Output is correct
17 Correct 71 ms 31056 KB Output is correct
18 Correct 58 ms 29172 KB Output is correct
19 Correct 80 ms 31056 KB Output is correct
20 Correct 65 ms 29012 KB Output is correct
21 Correct 55 ms 29012 KB Output is correct
22 Correct 55 ms 31056 KB Output is correct
23 Correct 64 ms 30804 KB Output is correct
24 Correct 61 ms 24660 KB Output is correct
25 Correct 59 ms 26704 KB Output is correct
26 Correct 57 ms 24656 KB Output is correct
27 Correct 109 ms 37204 KB Output is correct
28 Correct 97 ms 37168 KB Output is correct
29 Correct 96 ms 37076 KB Output is correct
30 Correct 116 ms 35692 KB Output is correct
31 Correct 98 ms 37200 KB Output is correct
32 Correct 89 ms 36516 KB Output is correct
33 Correct 80 ms 36432 KB Output is correct
34 Correct 82 ms 36184 KB Output is correct
35 Correct 78 ms 36180 KB Output is correct
36 Correct 82 ms 36188 KB Output is correct
37 Correct 77 ms 36364 KB Output is correct
38 Correct 146 ms 51140 KB Output is correct
39 Correct 156 ms 54608 KB Output is correct
40 Correct 141 ms 46672 KB Output is correct
41 Correct 197 ms 52816 KB Output is correct
42 Correct 94 ms 37456 KB Output is correct
43 Correct 119 ms 37432 KB Output is correct
44 Correct 118 ms 43084 KB Output is correct
45 Correct 120 ms 43424 KB Output is correct
46 Correct 118 ms 43348 KB Output is correct
47 Correct 89 ms 37460 KB Output is correct
48 Correct 87 ms 37204 KB Output is correct
49 Correct 142 ms 43096 KB Output is correct
50 Correct 121 ms 43344 KB Output is correct
51 Correct 115 ms 43628 KB Output is correct
52 Correct 122 ms 42352 KB Output is correct
53 Correct 141 ms 46936 KB Output is correct
54 Correct 151 ms 51904 KB Output is correct
55 Correct 131 ms 47080 KB Output is correct