답안 #1081651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081651 2024-08-30T08:48:52 Z daoquanglinh2007 Long Mansion (JOI17_long_mansion) C++17
10 / 100
3000 ms 26996 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 ((curr == N || pre[curr] < curl) && (curl == 1 || nxt[curl] > curr)) break;
        if (curr < N && pre[curr] >= curl){
            curr++;
        }
        else if (curl > 1 && nxt[curl] <= curr){
            curl--;
            curl = min(curl, l[curl]);
            curr = max(curr, r[curr]);
        }
        if (l[curl] <= u && r[curl] >= u){
            l[u] = l[curl];
            r[u] = r[curl];
            return;
        }
        if (l[curr] <= u && r[curr] >= u){
            l[u] = l[curr];
            r[u] = r[curr];
            return;
        }
    }
    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 7 ms 12376 KB Output is correct
2 Correct 9 ms 12636 KB Output is correct
3 Correct 18 ms 12636 KB Output is correct
4 Correct 11 ms 12380 KB Output is correct
5 Correct 10 ms 12352 KB Output is correct
6 Correct 7 ms 12376 KB Output is correct
7 Correct 7 ms 12444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12376 KB Output is correct
2 Correct 9 ms 12636 KB Output is correct
3 Correct 18 ms 12636 KB Output is correct
4 Correct 11 ms 12380 KB Output is correct
5 Correct 10 ms 12352 KB Output is correct
6 Correct 7 ms 12376 KB Output is correct
7 Correct 7 ms 12444 KB Output is correct
8 Correct 66 ms 18248 KB Output is correct
9 Correct 65 ms 18004 KB Output is correct
10 Correct 92 ms 18632 KB Output is correct
11 Correct 75 ms 18772 KB Output is correct
12 Correct 66 ms 17696 KB Output is correct
13 Correct 61 ms 18260 KB Output is correct
14 Correct 58 ms 18260 KB Output is correct
15 Correct 61 ms 18256 KB Output is correct
16 Correct 61 ms 18256 KB Output is correct
17 Correct 59 ms 18256 KB Output is correct
18 Correct 62 ms 18268 KB Output is correct
19 Correct 63 ms 18256 KB Output is correct
20 Correct 60 ms 18256 KB Output is correct
21 Correct 66 ms 18264 KB Output is correct
22 Correct 60 ms 18280 KB Output is correct
23 Correct 86 ms 18000 KB Output is correct
24 Correct 64 ms 18000 KB Output is correct
25 Correct 66 ms 17980 KB Output is correct
26 Correct 61 ms 18112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 935 ms 26996 KB Output is correct
2 Correct 1790 ms 26804 KB Output is correct
3 Execution timed out 3054 ms 19028 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12376 KB Output is correct
2 Correct 9 ms 12636 KB Output is correct
3 Correct 18 ms 12636 KB Output is correct
4 Correct 11 ms 12380 KB Output is correct
5 Correct 10 ms 12352 KB Output is correct
6 Correct 7 ms 12376 KB Output is correct
7 Correct 7 ms 12444 KB Output is correct
8 Correct 66 ms 18248 KB Output is correct
9 Correct 65 ms 18004 KB Output is correct
10 Correct 92 ms 18632 KB Output is correct
11 Correct 75 ms 18772 KB Output is correct
12 Correct 66 ms 17696 KB Output is correct
13 Correct 61 ms 18260 KB Output is correct
14 Correct 58 ms 18260 KB Output is correct
15 Correct 61 ms 18256 KB Output is correct
16 Correct 61 ms 18256 KB Output is correct
17 Correct 59 ms 18256 KB Output is correct
18 Correct 62 ms 18268 KB Output is correct
19 Correct 63 ms 18256 KB Output is correct
20 Correct 60 ms 18256 KB Output is correct
21 Correct 66 ms 18264 KB Output is correct
22 Correct 60 ms 18280 KB Output is correct
23 Correct 86 ms 18000 KB Output is correct
24 Correct 64 ms 18000 KB Output is correct
25 Correct 66 ms 17980 KB Output is correct
26 Correct 61 ms 18112 KB Output is correct
27 Correct 935 ms 26996 KB Output is correct
28 Correct 1790 ms 26804 KB Output is correct
29 Execution timed out 3054 ms 19028 KB Time limit exceeded
30 Halted 0 ms 0 KB -