답안 #282445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282445 2020-08-24T12:29:55 Z MKopchev Long Mansion (JOI17_long_mansion) C++14
100 / 100
446 ms 43192 KB
#include<bits/stdc++.h>
using namespace std;

const int nmax=5e5+42;

int n,inp[nmax];

vector<int> seen[nmax];

int can_l[nmax],can_r[nmax];

bool test(int val,int l,int r)
{
    if(seen[val].size()==0)return 0;

    int p=lower_bound(seen[val].begin(),seen[val].end(),l)-seen[val].begin();

    if(p<seen[val].size()&&seen[val][p]<=r)return 1;

    return 0;
}
int main()
{
    scanf("%i",&n);

    for(int i=1;i<n;i++)scanf("%i",&inp[i]);

    for(int i=1;i<=n;i++)
    {
        int sz,val;
        scanf("%i",&sz);

        for(int j=1;j<=sz;j++)
        {
            scanf("%i",&val);
            seen[val].push_back(i);
        }
    }

    for(int i=1;i<=n;i++)
    {
        can_l[i]=i;
        can_r[i]=i;

        while(can_l[i]!=1||can_r[i]!=n)
        {
            if(can_l[i]!=1&&test(inp[can_l[i]-1],can_l[i],can_r[i]))
            {
                can_l[i]--;

                can_r[i]=max(can_r[i],can_r[can_l[i]]);

                can_l[i]=min(can_l[i],can_l[can_l[i]]);
            }
            else if(can_r[i]!=n&&test(inp[can_r[i]],can_l[i],can_r[i]))can_r[i]++;
            else break;
        }
    }

    int q;
    scanf("%i",&q);

    for(int i=1;i<=q;i++)
    {
        int le,ri;
        scanf("%i%i",&le,&ri);

        if(can_l[le]<=ri&&ri<=can_r[le])printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Compilation message

long_mansion.cpp: In function 'bool test(int, int, int)':
long_mansion.cpp:18:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     if(p<seen[val].size()&&seen[val][p]<=r)return 1;
      |        ~^~~~~~~~~~~~~~~~~
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     scanf("%i",&n);
      |     ~~~~~^~~~~~~~~
long_mansion.cpp:26:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     for(int i=1;i<n;i++)scanf("%i",&inp[i]);
      |                         ~~~~~^~~~~~~~~~~~~~
long_mansion.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |         scanf("%i",&sz);
      |         ~~~~~^~~~~~~~~~
long_mansion.cpp:35:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |             scanf("%i",&val);
      |             ~~~~~^~~~~~~~~~~
long_mansion.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |     scanf("%i",&q);
      |     ~~~~~^~~~~~~~~
long_mansion.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |         scanf("%i%i",&le,&ri);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12160 KB Output is correct
2 Correct 12 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 11 ms 12288 KB Output is correct
5 Correct 12 ms 12160 KB Output is correct
6 Correct 12 ms 12288 KB Output is correct
7 Correct 13 ms 12288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12160 KB Output is correct
2 Correct 12 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 11 ms 12288 KB Output is correct
5 Correct 12 ms 12160 KB Output is correct
6 Correct 12 ms 12288 KB Output is correct
7 Correct 13 ms 12288 KB Output is correct
8 Correct 155 ms 14840 KB Output is correct
9 Correct 165 ms 14712 KB Output is correct
10 Correct 155 ms 14840 KB Output is correct
11 Correct 157 ms 16760 KB Output is correct
12 Correct 157 ms 16504 KB Output is correct
13 Correct 148 ms 16504 KB Output is correct
14 Correct 150 ms 16504 KB Output is correct
15 Correct 154 ms 16552 KB Output is correct
16 Correct 136 ms 16760 KB Output is correct
17 Correct 147 ms 16504 KB Output is correct
18 Correct 146 ms 16508 KB Output is correct
19 Correct 147 ms 16504 KB Output is correct
20 Correct 146 ms 16780 KB Output is correct
21 Correct 140 ms 16764 KB Output is correct
22 Correct 151 ms 16704 KB Output is correct
23 Correct 152 ms 16376 KB Output is correct
24 Correct 154 ms 16428 KB Output is correct
25 Correct 152 ms 16376 KB Output is correct
26 Correct 152 ms 16376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 19192 KB Output is correct
2 Correct 265 ms 17912 KB Output is correct
3 Correct 263 ms 18084 KB Output is correct
4 Correct 272 ms 18168 KB Output is correct
5 Correct 269 ms 18168 KB Output is correct
6 Correct 228 ms 17144 KB Output is correct
7 Correct 224 ms 17656 KB Output is correct
8 Correct 214 ms 17400 KB Output is correct
9 Correct 223 ms 17528 KB Output is correct
10 Correct 221 ms 17400 KB Output is correct
11 Correct 211 ms 17656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12160 KB Output is correct
2 Correct 12 ms 12288 KB Output is correct
3 Correct 12 ms 12288 KB Output is correct
4 Correct 11 ms 12288 KB Output is correct
5 Correct 12 ms 12160 KB Output is correct
6 Correct 12 ms 12288 KB Output is correct
7 Correct 13 ms 12288 KB Output is correct
8 Correct 155 ms 14840 KB Output is correct
9 Correct 165 ms 14712 KB Output is correct
10 Correct 155 ms 14840 KB Output is correct
11 Correct 157 ms 16760 KB Output is correct
12 Correct 157 ms 16504 KB Output is correct
13 Correct 148 ms 16504 KB Output is correct
14 Correct 150 ms 16504 KB Output is correct
15 Correct 154 ms 16552 KB Output is correct
16 Correct 136 ms 16760 KB Output is correct
17 Correct 147 ms 16504 KB Output is correct
18 Correct 146 ms 16508 KB Output is correct
19 Correct 147 ms 16504 KB Output is correct
20 Correct 146 ms 16780 KB Output is correct
21 Correct 140 ms 16764 KB Output is correct
22 Correct 151 ms 16704 KB Output is correct
23 Correct 152 ms 16376 KB Output is correct
24 Correct 154 ms 16428 KB Output is correct
25 Correct 152 ms 16376 KB Output is correct
26 Correct 152 ms 16376 KB Output is correct
27 Correct 279 ms 19192 KB Output is correct
28 Correct 265 ms 17912 KB Output is correct
29 Correct 263 ms 18084 KB Output is correct
30 Correct 272 ms 18168 KB Output is correct
31 Correct 269 ms 18168 KB Output is correct
32 Correct 228 ms 17144 KB Output is correct
33 Correct 224 ms 17656 KB Output is correct
34 Correct 214 ms 17400 KB Output is correct
35 Correct 223 ms 17528 KB Output is correct
36 Correct 221 ms 17400 KB Output is correct
37 Correct 211 ms 17656 KB Output is correct
38 Correct 420 ms 31864 KB Output is correct
39 Correct 439 ms 33912 KB Output is correct
40 Correct 386 ms 31120 KB Output is correct
41 Correct 446 ms 31456 KB Output is correct
42 Correct 240 ms 24184 KB Output is correct
43 Correct 243 ms 23928 KB Output is correct
44 Correct 391 ms 29760 KB Output is correct
45 Correct 385 ms 30200 KB Output is correct
46 Correct 413 ms 30456 KB Output is correct
47 Correct 259 ms 24396 KB Output is correct
48 Correct 241 ms 23672 KB Output is correct
49 Correct 352 ms 29304 KB Output is correct
50 Correct 392 ms 29816 KB Output is correct
51 Correct 417 ms 30900 KB Output is correct
52 Correct 319 ms 31324 KB Output is correct
53 Correct 347 ms 36852 KB Output is correct
54 Correct 409 ms 43192 KB Output is correct
55 Correct 359 ms 37372 KB Output is correct