답안 #1092770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092770 2024-09-25T02:59:59 Z 12345678 Long Mansion (JOI17_long_mansion) C++17
100 / 100
201 ms 52476 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=5e5+5;

int n, lstl[nx], lstr[nx], l[nx], r[nx], x, y, qrs, lst[nx], c[nx];
vector<int> d[nx];

void solve(int vl, int vr)
{
    if (vl==vr) return l[vl]=r[vl]=vl, void();
    int md=(vl+vr)/2, cl=md, cr=md;
    solve(vl, md);
    solve(md+1, vr);
    for (int i=md; i>=vl; i--)
    {
        if (r[i]==md)
        {
            cl=min(cl, l[i]);
            while (1)
            {
                if (vl<cl&&lstr[cl]<=cr) cl--;
                else if (cr<vr&&lstl[cr]>=cl) cr++;
                else break;
            }
            l[i]=cl;
            r[i]=cr;
        }
    }
    cl=cr=md+1;
    for (int i=md+1; i<=vr; i++)
    {
        if (l[i]==md+1)
        {
            cr=max(cr, r[i]);
            while (1)
            {
                if (vl<cl&&lstr[cl]<=cr) cl--;
                else if (cr<vr&&lstl[cr]>=cl) cr++;
                else break;
            }
            l[i]=cl;
            r[i]=cr;
        }
    }
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<n; i++) cin>>c[i];
    for (int i=1; i<=n; i++)
    {
        cin>>x;
        for (int j=1; j<=x; j++) cin>>y, d[i].push_back(y);
    }
    for (int i=1; i<n; i++)
    {
        for (auto x:d[i]) lst[x]=i;
        lstl[i]=lst[c[i]];
    }
    for (int i=1; i<=n; i++) lst[i]=n+1;
    for (int i=n; i>1; i--)
    {
        for (auto x:d[i]) lst[x]=i;
        lstr[i]=lst[c[i-1]];
    }
    solve(1, n);
    cin>>qrs;
    while (qrs--)
    {
        cin>>x>>y;
        if (l[x]<=y&&y<=r[x]) cout<<"YES\n";
        else cout<<"NO\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12376 KB Output is correct
2 Correct 7 ms 12380 KB Output is correct
3 Correct 7 ms 12380 KB Output is correct
4 Correct 6 ms 12324 KB Output is correct
5 Correct 6 ms 12436 KB Output is correct
6 Correct 7 ms 12376 KB Output is correct
7 Correct 6 ms 12384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12376 KB Output is correct
2 Correct 7 ms 12380 KB Output is correct
3 Correct 7 ms 12380 KB Output is correct
4 Correct 6 ms 12324 KB Output is correct
5 Correct 6 ms 12436 KB Output is correct
6 Correct 7 ms 12376 KB Output is correct
7 Correct 6 ms 12384 KB Output is correct
8 Correct 61 ms 18256 KB Output is correct
9 Correct 61 ms 18000 KB Output is correct
10 Correct 67 ms 18516 KB Output is correct
11 Correct 63 ms 18916 KB Output is correct
12 Correct 58 ms 17744 KB Output is correct
13 Correct 63 ms 18256 KB Output is correct
14 Correct 62 ms 18396 KB Output is correct
15 Correct 61 ms 18420 KB Output is correct
16 Correct 58 ms 18000 KB Output is correct
17 Correct 58 ms 18232 KB Output is correct
18 Correct 69 ms 18368 KB Output is correct
19 Correct 56 ms 18332 KB Output is correct
20 Correct 65 ms 18200 KB Output is correct
21 Correct 66 ms 18236 KB Output is correct
22 Correct 83 ms 18240 KB Output is correct
23 Correct 70 ms 18096 KB Output is correct
24 Correct 77 ms 17996 KB Output is correct
25 Correct 74 ms 18148 KB Output is correct
26 Correct 71 ms 18052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 27112 KB Output is correct
2 Correct 118 ms 26960 KB Output is correct
3 Correct 130 ms 26704 KB Output is correct
4 Correct 109 ms 27272 KB Output is correct
5 Correct 113 ms 27032 KB Output is correct
6 Correct 89 ms 25860 KB Output is correct
7 Correct 91 ms 25656 KB Output is correct
8 Correct 88 ms 25688 KB Output is correct
9 Correct 86 ms 25596 KB Output is correct
10 Correct 84 ms 25680 KB Output is correct
11 Correct 89 ms 25680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12376 KB Output is correct
2 Correct 7 ms 12380 KB Output is correct
3 Correct 7 ms 12380 KB Output is correct
4 Correct 6 ms 12324 KB Output is correct
5 Correct 6 ms 12436 KB Output is correct
6 Correct 7 ms 12376 KB Output is correct
7 Correct 6 ms 12384 KB Output is correct
8 Correct 61 ms 18256 KB Output is correct
9 Correct 61 ms 18000 KB Output is correct
10 Correct 67 ms 18516 KB Output is correct
11 Correct 63 ms 18916 KB Output is correct
12 Correct 58 ms 17744 KB Output is correct
13 Correct 63 ms 18256 KB Output is correct
14 Correct 62 ms 18396 KB Output is correct
15 Correct 61 ms 18420 KB Output is correct
16 Correct 58 ms 18000 KB Output is correct
17 Correct 58 ms 18232 KB Output is correct
18 Correct 69 ms 18368 KB Output is correct
19 Correct 56 ms 18332 KB Output is correct
20 Correct 65 ms 18200 KB Output is correct
21 Correct 66 ms 18236 KB Output is correct
22 Correct 83 ms 18240 KB Output is correct
23 Correct 70 ms 18096 KB Output is correct
24 Correct 77 ms 17996 KB Output is correct
25 Correct 74 ms 18148 KB Output is correct
26 Correct 71 ms 18052 KB Output is correct
27 Correct 121 ms 27112 KB Output is correct
28 Correct 118 ms 26960 KB Output is correct
29 Correct 130 ms 26704 KB Output is correct
30 Correct 109 ms 27272 KB Output is correct
31 Correct 113 ms 27032 KB Output is correct
32 Correct 89 ms 25860 KB Output is correct
33 Correct 91 ms 25656 KB Output is correct
34 Correct 88 ms 25688 KB Output is correct
35 Correct 86 ms 25596 KB Output is correct
36 Correct 84 ms 25680 KB Output is correct
37 Correct 89 ms 25680 KB Output is correct
38 Correct 153 ms 47184 KB Output is correct
39 Correct 161 ms 52476 KB Output is correct
40 Correct 141 ms 40532 KB Output is correct
41 Correct 201 ms 50768 KB Output is correct
42 Correct 91 ms 26708 KB Output is correct
43 Correct 91 ms 26724 KB Output is correct
44 Correct 121 ms 34900 KB Output is correct
45 Correct 120 ms 34896 KB Output is correct
46 Correct 122 ms 35152 KB Output is correct
47 Correct 91 ms 26860 KB Output is correct
48 Correct 90 ms 26536 KB Output is correct
49 Correct 135 ms 34900 KB Output is correct
50 Correct 122 ms 34896 KB Output is correct
51 Correct 134 ms 35156 KB Output is correct
52 Correct 116 ms 33876 KB Output is correct
53 Correct 176 ms 41040 KB Output is correct
54 Correct 159 ms 47956 KB Output is correct
55 Correct 137 ms 41092 KB Output is correct