답안 #125483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125483 2019-07-05T13:12:53 Z songc Long Mansion (JOI17_long_mansion) C++14
100 / 100
1142 ms 72740 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int N, Q;
int C[505050], S[2020202], E[2020202];
int L[505050], R[505050], chk[505050];
int LT[2020202], RT[2020202];
vector<int> key[505050];

void init(int id, int s, int e){
    if (s == e){
        LT[id] = L[s];
        RT[id] = R[s];
        return;
    }
    int mid = (s+e)/2;
    init(id*2, s, mid);
    init(id*2+1, mid+1, e);
    LT[id] = min(LT[id*2], LT[id*2+1]);
    RT[id] = max(RT[id*2], RT[id*2+1]);
}

int Lquery(int id, int s, int e, int ts, int te, int x){
    if (e < ts || te < s || LT[id] > x) return -1;
    if (s == e) return s;
    int mid = (s+e)/2;
    int ret = Lquery(id*2+1, mid+1, e, ts, te, x);
    if (ret != -1) return ret;
    return Lquery(id*2, s, mid, ts, te, x);
}

int Rquery(int id, int s, int e, int ts, int te, int x){
    if (e < ts || te < s || RT[id] <= x) return -1;
    if (s == e) return s+1;
    int mid = (s+e)/2;
    int ret = Rquery(id*2, s, mid, ts, te, x);
    if (ret != -1) return ret;
    return Rquery(id*2+1, mid+1, e, ts, te, x);
}

void updS(int id, int s, int e, int ts, int te, int v){
    if (e < ts || te < s) return;
    if (ts <= s && e <= te){
        S[id] = max(S[id], v);
        return;
    }
    int mid = (s+e)/2;
    updS(id*2, s, mid, ts, te, v);
    updS(id*2+1, mid+1, e, ts, te, v);
}

void updE(int id, int s, int e, int ts, int te, int v){
    if (e < ts || te < s) return;
    if (ts <= s && e <= te){
        E[id] = min(E[id], v);
        return;
    }
    int mid = (s+e)/2;
    updE(id*2, s, mid, ts, te, v);
    updE(id*2+1, mid+1, e, ts, te, v);
}

int readS(int id, int s, int e, int t){
    if (e < t || t < s) return 0;
    if (s == e) return S[id];
    int mid = (s+e)/2;
    return max(S[id], max(readS(id*2, s, mid, t), readS(id*2+1, mid+1, e, t)));
}

int readE(int id, int s, int e, int t){
    if (e < t || t < s) return N+1;
    if (s == e) return E[id];
    int mid = (s+e)/2;
    return min(E[id], min(readE(id*2, s, mid, t), readE(id*2+1, mid+1, e, t)));
}

int main(){
    int x, y;
    scanf("%d", &N);
    for (int i=1; i<N; i++) scanf("%d", &C[i]);
    for (int i=1; i<=N; i++){
        scanf("%d", &x);
        for (int j=0; j<x; j++){
            scanf("%d", &y);
            key[i].push_back(y);
        }
    }
    for (int i=1; i<=N; i++){
        for (int k : key[i]) chk[k] = i;
        L[i] = chk[C[i]];
    }
    memset(chk, 1, sizeof chk);
    for (int i=N; i>=1; i--){
        for (int k : key[i]) chk[k] = i;
        R[i-1] = chk[C[i-1]];
    }
    init(1, 0, N);
    for (int i=1; i<=4*N; i++) S[i] = 1, E[i] = N;
    for (int i=0; i<=N; i++){
        int k = Lquery(1, 0, N, i+1, R[i]-1, i);
        if (k != -1) updS(1, 1, N, i+1, k, i+1);
    }
    for (int i=0; i<=N; i++){
        int k = Rquery(1, 0, N, L[i], i-1, i);
        if (k != -1) updE(1, 1, N, k, i, i);
    }
    scanf("%d", &Q);
    while (Q--){
        scanf("%d %d", &x, &y);
        if (readS(1, 1, N, x) <= y && y <= readE(1, 1, N, x)) puts("YES");
        else puts("NO");
    }
    return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
long_mansion.cpp:81:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i=1; i<N; i++) scanf("%d", &C[i]);
                             ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
long_mansion.cpp:85:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &y);
             ~~~~~^~~~~~~~~~
long_mansion.cpp:108:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &Q);
     ~~~~~^~~~~~~~~~
long_mansion.cpp:110:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 14456 KB Output is correct
2 Correct 20 ms 14584 KB Output is correct
3 Correct 21 ms 14840 KB Output is correct
4 Correct 19 ms 14456 KB Output is correct
5 Correct 19 ms 14456 KB Output is correct
6 Correct 19 ms 14564 KB Output is correct
7 Correct 19 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 14456 KB Output is correct
2 Correct 20 ms 14584 KB Output is correct
3 Correct 21 ms 14840 KB Output is correct
4 Correct 19 ms 14456 KB Output is correct
5 Correct 19 ms 14456 KB Output is correct
6 Correct 19 ms 14564 KB Output is correct
7 Correct 19 ms 14456 KB Output is correct
8 Correct 276 ms 20304 KB Output is correct
9 Correct 277 ms 20216 KB Output is correct
10 Correct 293 ms 20728 KB Output is correct
11 Correct 314 ms 21240 KB Output is correct
12 Correct 273 ms 19836 KB Output is correct
13 Correct 263 ms 20472 KB Output is correct
14 Correct 290 ms 20472 KB Output is correct
15 Correct 278 ms 20504 KB Output is correct
16 Correct 296 ms 20344 KB Output is correct
17 Correct 275 ms 20608 KB Output is correct
18 Correct 264 ms 20600 KB Output is correct
19 Correct 274 ms 20732 KB Output is correct
20 Correct 284 ms 20600 KB Output is correct
21 Correct 292 ms 20472 KB Output is correct
22 Correct 268 ms 20344 KB Output is correct
23 Correct 272 ms 20220 KB Output is correct
24 Correct 273 ms 20280 KB Output is correct
25 Correct 276 ms 20236 KB Output is correct
26 Correct 271 ms 20368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 541 ms 33320 KB Output is correct
2 Correct 549 ms 33196 KB Output is correct
3 Correct 545 ms 33116 KB Output is correct
4 Correct 549 ms 33272 KB Output is correct
5 Correct 538 ms 33348 KB Output is correct
6 Correct 515 ms 31956 KB Output is correct
7 Correct 507 ms 31788 KB Output is correct
8 Correct 496 ms 31736 KB Output is correct
9 Correct 489 ms 31768 KB Output is correct
10 Correct 508 ms 31704 KB Output is correct
11 Correct 496 ms 31828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 14456 KB Output is correct
2 Correct 20 ms 14584 KB Output is correct
3 Correct 21 ms 14840 KB Output is correct
4 Correct 19 ms 14456 KB Output is correct
5 Correct 19 ms 14456 KB Output is correct
6 Correct 19 ms 14564 KB Output is correct
7 Correct 19 ms 14456 KB Output is correct
8 Correct 276 ms 20304 KB Output is correct
9 Correct 277 ms 20216 KB Output is correct
10 Correct 293 ms 20728 KB Output is correct
11 Correct 314 ms 21240 KB Output is correct
12 Correct 273 ms 19836 KB Output is correct
13 Correct 263 ms 20472 KB Output is correct
14 Correct 290 ms 20472 KB Output is correct
15 Correct 278 ms 20504 KB Output is correct
16 Correct 296 ms 20344 KB Output is correct
17 Correct 275 ms 20608 KB Output is correct
18 Correct 264 ms 20600 KB Output is correct
19 Correct 274 ms 20732 KB Output is correct
20 Correct 284 ms 20600 KB Output is correct
21 Correct 292 ms 20472 KB Output is correct
22 Correct 268 ms 20344 KB Output is correct
23 Correct 272 ms 20220 KB Output is correct
24 Correct 273 ms 20280 KB Output is correct
25 Correct 276 ms 20236 KB Output is correct
26 Correct 271 ms 20368 KB Output is correct
27 Correct 541 ms 33320 KB Output is correct
28 Correct 549 ms 33196 KB Output is correct
29 Correct 545 ms 33116 KB Output is correct
30 Correct 549 ms 33272 KB Output is correct
31 Correct 538 ms 33348 KB Output is correct
32 Correct 515 ms 31956 KB Output is correct
33 Correct 507 ms 31788 KB Output is correct
34 Correct 496 ms 31736 KB Output is correct
35 Correct 489 ms 31768 KB Output is correct
36 Correct 508 ms 31704 KB Output is correct
37 Correct 496 ms 31828 KB Output is correct
38 Correct 1110 ms 65484 KB Output is correct
39 Correct 1142 ms 72740 KB Output is correct
40 Correct 901 ms 56952 KB Output is correct
41 Correct 924 ms 71032 KB Output is correct
42 Correct 465 ms 32888 KB Output is correct
43 Correct 465 ms 32976 KB Output is correct
44 Correct 613 ms 45060 KB Output is correct
45 Correct 605 ms 45224 KB Output is correct
46 Correct 601 ms 45328 KB Output is correct
47 Correct 470 ms 33000 KB Output is correct
48 Correct 488 ms 32684 KB Output is correct
49 Correct 588 ms 45012 KB Output is correct
50 Correct 595 ms 45104 KB Output is correct
51 Correct 604 ms 45480 KB Output is correct
52 Correct 685 ms 43904 KB Output is correct
53 Correct 822 ms 57228 KB Output is correct
54 Correct 990 ms 66284 KB Output is correct
55 Correct 818 ms 57328 KB Output is correct