답안 #1063044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063044 2024-08-17T13:38:41 Z Andrey Long Mansion (JOI17_long_mansion) C++14
100 / 100
293 ms 48572 KB
#include<bits/stdc++.h>
using namespace std;

int n;
vector<int> haha[500001];
vector<int> idk(500001);
vector<bool> bruh(500001);
vector<pair<int,int>> ans(500001);
vector<int> roll(0);

void troll() {
    for(int i = 0; i < roll.size(); i++) {
        bruh[roll[i]] = false;
    }
    roll.clear();
}

void ins(int a) {
    for(int v: haha[a]) {
        bruh[v] = true;
        roll.push_back(v);
    }
}

void dude(int l, int r) {
    if(l == r) {
        ans[l] = {l,l};
        return;
    }
    int mid = (l+r)/2;
    dude(l,mid);
    dude(mid+1,r);
    int ql = mid+1,qr = mid;
    for(int i = mid+1; i <= r; i++) {
        if(qr < i) {
            qr = i;
            ins(qr);
            while(true) {
                if(ql > l && bruh[idk[ql-1]]) {
                    ql--;
                    ins(ql);
                }
                else if(qr < r && bruh[idk[qr]]) {
                    qr++;
                    ins(qr);
                }
                else {
                    break;
                }
            }
        }
        if(ans[i].first == mid+1) {
            ans[i] = {ql,qr};
        }
    }
    troll();
    ql = mid+1,qr = mid;
    for(int i = mid; i >= l; i--) {
        if(ql > i) {
            ql = i;
            ins(ql);
            while(true) {
                if(ql > l && bruh[idk[ql-1]]) {
                    ql--;
                    ins(ql);
                }
                else if(qr < r && bruh[idk[qr]]) {
                    qr++;
                    ins(qr);
                }
                else {
                    break;
                }
            }
        }
        if(ans[i].second == mid) {
            ans[i] = {ql,qr};
        }
    }
    troll();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i = 1; i < n; i++) {
        cin >> idk[i];
    }
    for(int i = 1; i <= n; i++) {
        int k,a;
        cin >> k;
        for(int j = 0; j < k; j++) {
            cin >> a;
            haha[i].push_back(a);
        }
    }
    dude(1,n);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        int x,y;
        cin >> x >> y;
        if(y >= ans[x].first && y <= ans[x].second) {
            cout << "YES\n";
        }
        else {
            cout << "NO\n";
        }
    }
    return 0;
}

Compilation message

long_mansion.cpp: In function 'void troll()':
long_mansion.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < roll.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 18268 KB Output is correct
2 Correct 11 ms 18268 KB Output is correct
3 Correct 10 ms 18268 KB Output is correct
4 Correct 11 ms 18156 KB Output is correct
5 Correct 8 ms 18268 KB Output is correct
6 Correct 12 ms 18416 KB Output is correct
7 Correct 9 ms 18268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 18268 KB Output is correct
2 Correct 11 ms 18268 KB Output is correct
3 Correct 10 ms 18268 KB Output is correct
4 Correct 11 ms 18156 KB Output is correct
5 Correct 8 ms 18268 KB Output is correct
6 Correct 12 ms 18416 KB Output is correct
7 Correct 9 ms 18268 KB Output is correct
8 Correct 65 ms 24148 KB Output is correct
9 Correct 84 ms 23904 KB Output is correct
10 Correct 66 ms 24356 KB Output is correct
11 Correct 99 ms 24744 KB Output is correct
12 Correct 58 ms 23540 KB Output is correct
13 Correct 64 ms 24152 KB Output is correct
14 Correct 68 ms 24380 KB Output is correct
15 Correct 92 ms 24164 KB Output is correct
16 Correct 57 ms 24156 KB Output is correct
17 Correct 61 ms 24148 KB Output is correct
18 Correct 62 ms 24236 KB Output is correct
19 Correct 90 ms 24148 KB Output is correct
20 Correct 58 ms 24120 KB Output is correct
21 Correct 55 ms 24120 KB Output is correct
22 Correct 58 ms 24148 KB Output is correct
23 Correct 64 ms 23892 KB Output is correct
24 Correct 62 ms 23860 KB Output is correct
25 Correct 61 ms 23892 KB Output is correct
26 Correct 66 ms 23888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 32708 KB Output is correct
2 Correct 167 ms 32456 KB Output is correct
3 Correct 167 ms 32152 KB Output is correct
4 Correct 169 ms 32460 KB Output is correct
5 Correct 162 ms 32448 KB Output is correct
6 Correct 126 ms 30152 KB Output is correct
7 Correct 119 ms 30012 KB Output is correct
8 Correct 112 ms 30124 KB Output is correct
9 Correct 110 ms 30108 KB Output is correct
10 Correct 108 ms 30172 KB Output is correct
11 Correct 142 ms 30156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 18268 KB Output is correct
2 Correct 11 ms 18268 KB Output is correct
3 Correct 10 ms 18268 KB Output is correct
4 Correct 11 ms 18156 KB Output is correct
5 Correct 8 ms 18268 KB Output is correct
6 Correct 12 ms 18416 KB Output is correct
7 Correct 9 ms 18268 KB Output is correct
8 Correct 65 ms 24148 KB Output is correct
9 Correct 84 ms 23904 KB Output is correct
10 Correct 66 ms 24356 KB Output is correct
11 Correct 99 ms 24744 KB Output is correct
12 Correct 58 ms 23540 KB Output is correct
13 Correct 64 ms 24152 KB Output is correct
14 Correct 68 ms 24380 KB Output is correct
15 Correct 92 ms 24164 KB Output is correct
16 Correct 57 ms 24156 KB Output is correct
17 Correct 61 ms 24148 KB Output is correct
18 Correct 62 ms 24236 KB Output is correct
19 Correct 90 ms 24148 KB Output is correct
20 Correct 58 ms 24120 KB Output is correct
21 Correct 55 ms 24120 KB Output is correct
22 Correct 58 ms 24148 KB Output is correct
23 Correct 64 ms 23892 KB Output is correct
24 Correct 62 ms 23860 KB Output is correct
25 Correct 61 ms 23892 KB Output is correct
26 Correct 66 ms 23888 KB Output is correct
27 Correct 166 ms 32708 KB Output is correct
28 Correct 167 ms 32456 KB Output is correct
29 Correct 167 ms 32152 KB Output is correct
30 Correct 169 ms 32460 KB Output is correct
31 Correct 162 ms 32448 KB Output is correct
32 Correct 126 ms 30152 KB Output is correct
33 Correct 119 ms 30012 KB Output is correct
34 Correct 112 ms 30124 KB Output is correct
35 Correct 110 ms 30108 KB Output is correct
36 Correct 108 ms 30172 KB Output is correct
37 Correct 142 ms 30156 KB Output is correct
38 Correct 228 ms 45760 KB Output is correct
39 Correct 236 ms 48572 KB Output is correct
40 Correct 223 ms 41672 KB Output is correct
41 Correct 293 ms 47164 KB Output is correct
42 Correct 109 ms 30668 KB Output is correct
43 Correct 112 ms 30924 KB Output is correct
44 Correct 174 ms 37068 KB Output is correct
45 Correct 155 ms 37212 KB Output is correct
46 Correct 159 ms 37320 KB Output is correct
47 Correct 113 ms 31356 KB Output is correct
48 Correct 113 ms 31164 KB Output is correct
49 Correct 172 ms 38020 KB Output is correct
50 Correct 167 ms 37068 KB Output is correct
51 Correct 170 ms 37836 KB Output is correct
52 Correct 142 ms 36024 KB Output is correct
53 Correct 181 ms 41412 KB Output is correct
54 Correct 218 ms 46380 KB Output is correct
55 Correct 174 ms 41412 KB Output is correct