답안 #83516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83516 2018-11-08T17:03:51 Z nikolapesic2802 Long Mansion (JOI17_long_mansion) C++14
25 / 100
441 ms 263168 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; ///find_by_order(),order_of_key()
const int N=5*1e5+5;
vector<int> hi(N),lo(N),l(N),r(N);
bool on(int l,int r,int x){return x>=l&&x<=r;}
bool can(int l,int r,int x){return on(l,r,hi[x])||on(l,r,lo[x]);}
int main()
{
    int n;
    scanf("%i",&n);
    vector<int> cor(n-1);
    for(int i=0;i<n-1;i++)
        scanf("%i",&cor[i]);
    vector<vector<int> > sobe(n);
    for(int i=0;i<n;i++)
    {
        int b;
        scanf("%i",&b);
        for(int j=0;j<b;j++)
        {
            int a;
            scanf("%i",&a);
            sobe[i].pb(a);
        }
    }
    vector<int> keys(n,-1);
    for(int i=0;i<n-1;i++)
    {
        for(auto p:sobe[i])
            keys[p]=i;
        lo[i]=keys[cor[i]];
    }
    fill(keys.begin(),keys.end(),-1);
    for(int i=n-1;i>0;i--)
    {
        for(auto p:sobe[i])
            keys[p]=i;
        hi[i-1]=keys[cor[i-1]];
    }
    for(int i=0;i<n;i++)
    {
        l[i]=r[i]=i;
        while(true)
        {
            if(l[i]>0&&can(l[i],r[i],l[i]-1))
            {
                r[i]=max(r[i],r[l[i]-1]);
                l[i]=l[l[i]-1];
            }
            else
                if(r[i]<n-1&&can(l[i],r[i],r[i]))
                    r[i]++;
                else
                    break;
        }
    }
    int q;
    scanf("%i",&q);
    for(int i=0;i<q;i++)
    {
        int x,y;
        scanf("%i %i",&x,&y);
        x--;
        y--;
        if(on(l[x],r[x],y))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
long_mansion.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&cor[i]);
         ~~~~~^~~~~~~~~~~~~~
long_mansion.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&b);
         ~~~~~^~~~~~~~~
long_mansion.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%i",&a);
             ~~~~~^~~~~~~~~
long_mansion.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&q);
     ~~~~~^~~~~~~~~
long_mansion.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8312 KB Output is correct
2 Correct 12 ms 8444 KB Output is correct
3 Correct 16 ms 8716 KB Output is correct
4 Correct 11 ms 8716 KB Output is correct
5 Correct 12 ms 8768 KB Output is correct
6 Correct 12 ms 8936 KB Output is correct
7 Correct 11 ms 9008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8312 KB Output is correct
2 Correct 12 ms 8444 KB Output is correct
3 Correct 16 ms 8716 KB Output is correct
4 Correct 11 ms 8716 KB Output is correct
5 Correct 12 ms 8768 KB Output is correct
6 Correct 12 ms 8936 KB Output is correct
7 Correct 11 ms 9008 KB Output is correct
8 Correct 156 ms 15056 KB Output is correct
9 Correct 150 ms 19464 KB Output is correct
10 Correct 150 ms 24168 KB Output is correct
11 Correct 157 ms 29112 KB Output is correct
12 Correct 145 ms 32548 KB Output is correct
13 Correct 149 ms 37004 KB Output is correct
14 Correct 207 ms 41380 KB Output is correct
15 Correct 143 ms 45764 KB Output is correct
16 Correct 145 ms 49920 KB Output is correct
17 Correct 146 ms 54092 KB Output is correct
18 Correct 149 ms 58432 KB Output is correct
19 Correct 153 ms 62920 KB Output is correct
20 Correct 184 ms 67384 KB Output is correct
21 Correct 140 ms 71200 KB Output is correct
22 Correct 159 ms 75116 KB Output is correct
23 Correct 148 ms 79356 KB Output is correct
24 Correct 162 ms 83516 KB Output is correct
25 Correct 155 ms 87812 KB Output is correct
26 Correct 148 ms 92196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 298 ms 104572 KB Output is correct
2 Correct 390 ms 111792 KB Output is correct
3 Correct 277 ms 118736 KB Output is correct
4 Correct 313 ms 126076 KB Output is correct
5 Correct 331 ms 133272 KB Output is correct
6 Correct 225 ms 138828 KB Output is correct
7 Correct 214 ms 145040 KB Output is correct
8 Correct 239 ms 150272 KB Output is correct
9 Correct 227 ms 156292 KB Output is correct
10 Correct 218 ms 162252 KB Output is correct
11 Correct 250 ms 167548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 8312 KB Output is correct
2 Correct 12 ms 8444 KB Output is correct
3 Correct 16 ms 8716 KB Output is correct
4 Correct 11 ms 8716 KB Output is correct
5 Correct 12 ms 8768 KB Output is correct
6 Correct 12 ms 8936 KB Output is correct
7 Correct 11 ms 9008 KB Output is correct
8 Correct 156 ms 15056 KB Output is correct
9 Correct 150 ms 19464 KB Output is correct
10 Correct 150 ms 24168 KB Output is correct
11 Correct 157 ms 29112 KB Output is correct
12 Correct 145 ms 32548 KB Output is correct
13 Correct 149 ms 37004 KB Output is correct
14 Correct 207 ms 41380 KB Output is correct
15 Correct 143 ms 45764 KB Output is correct
16 Correct 145 ms 49920 KB Output is correct
17 Correct 146 ms 54092 KB Output is correct
18 Correct 149 ms 58432 KB Output is correct
19 Correct 153 ms 62920 KB Output is correct
20 Correct 184 ms 67384 KB Output is correct
21 Correct 140 ms 71200 KB Output is correct
22 Correct 159 ms 75116 KB Output is correct
23 Correct 148 ms 79356 KB Output is correct
24 Correct 162 ms 83516 KB Output is correct
25 Correct 155 ms 87812 KB Output is correct
26 Correct 148 ms 92196 KB Output is correct
27 Correct 298 ms 104572 KB Output is correct
28 Correct 390 ms 111792 KB Output is correct
29 Correct 277 ms 118736 KB Output is correct
30 Correct 313 ms 126076 KB Output is correct
31 Correct 331 ms 133272 KB Output is correct
32 Correct 225 ms 138828 KB Output is correct
33 Correct 214 ms 145040 KB Output is correct
34 Correct 239 ms 150272 KB Output is correct
35 Correct 227 ms 156292 KB Output is correct
36 Correct 218 ms 162252 KB Output is correct
37 Correct 250 ms 167548 KB Output is correct
38 Correct 434 ms 196668 KB Output is correct
39 Correct 441 ms 214464 KB Output is correct
40 Correct 388 ms 214464 KB Output is correct
41 Correct 435 ms 233416 KB Output is correct
42 Correct 232 ms 233416 KB Output is correct
43 Correct 253 ms 233416 KB Output is correct
44 Correct 338 ms 238860 KB Output is correct
45 Correct 324 ms 247408 KB Output is correct
46 Correct 332 ms 257872 KB Output is correct
47 Correct 236 ms 259004 KB Output is correct
48 Runtime error 258 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
49 Halted 0 ms 0 KB -