답안 #363532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
363532 2021-02-06T13:05:41 Z denkendoemeer Long Mansion (JOI17_long_mansion) C++14
100 / 100
439 ms 52460 KB
#include<bits/stdc++.h>
using namespace std;
int c[500005],last[500005],pre[500005],nex[500005],st[500005],dr[500005];
vector<int>a[500005];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int n,i;
    scanf("%d",&n);
    for(i=1;i<n;i++)
        scanf("%d",&c[i]);
    for(i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        a[i].resize(x);
        int j;
        for(j=0;j<x;j++)
            scanf("%d",&a[i][j]);
    }
    for(i=1;i<n;i++){
        for(auto it:a[i])
            last[it]=i;
        pre[i]=last[c[i]];
    }
    for(i=1;i<=n;i++)
        last[i]=n+1;
    for(i=n;i>=2;i--){
        for(auto it:a[i])
            last[it]=i;
        nex[i-1]=last[c[i-1]];
    }
    for(i=1;i<=n;i++){
        int l=i,r=i;
        while(1){
            if (l>1 && nex[l-1]<=r){
                r=max(r,dr[l-1]);
                l=st[l-1];
                continue;
            }
            if (r+1<=n && pre[r]>=l){
                r++;
                continue;
            }
            break;
        }
        st[i]=l;
        dr[i]=r;
    }
    int q,x,y;
    scanf("%d",&q);
    for(i=1;i<=q;i++){
        scanf("%d%d",&x,&y);
        if (st[x]<=y && y<=dr[x])
            printf("YES\n");
        else
            printf("NO\n");
    }
return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
long_mansion.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |         scanf("%d",&c[i]);
      |         ~~~~~^~~~~~~~~~~~
long_mansion.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         scanf("%d",&x);
      |         ~~~~~^~~~~~~~~
long_mansion.cpp:19:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |             scanf("%d",&a[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~
long_mansion.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
long_mansion.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12268 KB Output is correct
2 Correct 11 ms 12396 KB Output is correct
3 Correct 12 ms 12524 KB Output is correct
4 Correct 11 ms 12268 KB Output is correct
5 Correct 11 ms 12268 KB Output is correct
6 Correct 11 ms 12268 KB Output is correct
7 Correct 11 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12268 KB Output is correct
2 Correct 11 ms 12396 KB Output is correct
3 Correct 12 ms 12524 KB Output is correct
4 Correct 11 ms 12268 KB Output is correct
5 Correct 11 ms 12268 KB Output is correct
6 Correct 11 ms 12268 KB Output is correct
7 Correct 11 ms 12268 KB Output is correct
8 Correct 176 ms 18156 KB Output is correct
9 Correct 148 ms 18300 KB Output is correct
10 Correct 151 ms 18540 KB Output is correct
11 Correct 148 ms 18924 KB Output is correct
12 Correct 139 ms 17772 KB Output is correct
13 Correct 143 ms 18500 KB Output is correct
14 Correct 146 ms 18412 KB Output is correct
15 Correct 158 ms 18412 KB Output is correct
16 Correct 138 ms 18156 KB Output is correct
17 Correct 144 ms 18284 KB Output is correct
18 Correct 145 ms 18412 KB Output is correct
19 Correct 166 ms 18412 KB Output is correct
20 Correct 142 ms 18284 KB Output is correct
21 Correct 140 ms 18376 KB Output is correct
22 Correct 142 ms 18284 KB Output is correct
23 Correct 142 ms 18156 KB Output is correct
24 Correct 143 ms 18156 KB Output is correct
25 Correct 144 ms 18156 KB Output is correct
26 Correct 142 ms 18156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 26604 KB Output is correct
2 Correct 270 ms 26632 KB Output is correct
3 Correct 237 ms 26348 KB Output is correct
4 Correct 238 ms 26604 KB Output is correct
5 Correct 298 ms 26624 KB Output is correct
6 Correct 206 ms 25964 KB Output is correct
7 Correct 213 ms 25788 KB Output is correct
8 Correct 198 ms 25580 KB Output is correct
9 Correct 194 ms 25580 KB Output is correct
10 Correct 245 ms 25580 KB Output is correct
11 Correct 193 ms 25580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12268 KB Output is correct
2 Correct 11 ms 12396 KB Output is correct
3 Correct 12 ms 12524 KB Output is correct
4 Correct 11 ms 12268 KB Output is correct
5 Correct 11 ms 12268 KB Output is correct
6 Correct 11 ms 12268 KB Output is correct
7 Correct 11 ms 12268 KB Output is correct
8 Correct 176 ms 18156 KB Output is correct
9 Correct 148 ms 18300 KB Output is correct
10 Correct 151 ms 18540 KB Output is correct
11 Correct 148 ms 18924 KB Output is correct
12 Correct 139 ms 17772 KB Output is correct
13 Correct 143 ms 18500 KB Output is correct
14 Correct 146 ms 18412 KB Output is correct
15 Correct 158 ms 18412 KB Output is correct
16 Correct 138 ms 18156 KB Output is correct
17 Correct 144 ms 18284 KB Output is correct
18 Correct 145 ms 18412 KB Output is correct
19 Correct 166 ms 18412 KB Output is correct
20 Correct 142 ms 18284 KB Output is correct
21 Correct 140 ms 18376 KB Output is correct
22 Correct 142 ms 18284 KB Output is correct
23 Correct 142 ms 18156 KB Output is correct
24 Correct 143 ms 18156 KB Output is correct
25 Correct 144 ms 18156 KB Output is correct
26 Correct 142 ms 18156 KB Output is correct
27 Correct 240 ms 26604 KB Output is correct
28 Correct 270 ms 26632 KB Output is correct
29 Correct 237 ms 26348 KB Output is correct
30 Correct 238 ms 26604 KB Output is correct
31 Correct 298 ms 26624 KB Output is correct
32 Correct 206 ms 25964 KB Output is correct
33 Correct 213 ms 25788 KB Output is correct
34 Correct 198 ms 25580 KB Output is correct
35 Correct 194 ms 25580 KB Output is correct
36 Correct 245 ms 25580 KB Output is correct
37 Correct 193 ms 25580 KB Output is correct
38 Correct 439 ms 47340 KB Output is correct
39 Correct 398 ms 52460 KB Output is correct
40 Correct 399 ms 40764 KB Output is correct
41 Correct 387 ms 50796 KB Output is correct
42 Correct 213 ms 26880 KB Output is correct
43 Correct 220 ms 26988 KB Output is correct
44 Correct 324 ms 34924 KB Output is correct
45 Correct 280 ms 35052 KB Output is correct
46 Correct 283 ms 35180 KB Output is correct
47 Correct 244 ms 26860 KB Output is correct
48 Correct 209 ms 26860 KB Output is correct
49 Correct 315 ms 34924 KB Output is correct
50 Correct 286 ms 34956 KB Output is correct
51 Correct 293 ms 35212 KB Output is correct
52 Correct 272 ms 33772 KB Output is correct
53 Correct 333 ms 41196 KB Output is correct
54 Correct 394 ms 48364 KB Output is correct
55 Correct 317 ms 41196 KB Output is correct