답안 #322014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
322014 2020-11-13T18:07:03 Z GioChkhaidze Long Mansion (JOI17_long_mansion) C++14
100 / 100
846 ms 119148 KB
#include <bits/stdc++.h>

using namespace std;
 
const int N=5e5+5;

int n,q,x,y;
int a[N],sz[N];
int L[N],R[N],ansl[N],ansr[N];

set < int > st[N];
set < int > :: iterator it;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL),cout.tie(NULL);
  
  cin>>n;
  for (int i=1; i<n; i++)
    cin>>a[i];
  
  for (int i=1; i<=n; i++) {
    cin>>sz[i];
    for (int j=1; j<=sz[i]; j++) {
      cin>>x;
      st[x].insert(i);
    }
  }
  
  for (int i=1; i<=n; i++)
    st[i].insert(-1),st[i].insert(n+1);
  
  for (int i=1; i<n; i++) {
    it=st[a[i]].upper_bound(i);
    R[i]=(*it);
    --it;
    L[i]=(*it);
  }

  for (int i=1; i<=n; i++) {
    ansl[i]=ansr[i]=i;
    while (1) {
      if (1<ansl[i] && R[ansl[i]-1]<=ansr[i]) {
        ansr[i]=max(ansr[i],ansr[ansl[i]-1]);
        ansl[i]=min(ansl[i],ansl[ansl[i]-1]);
      }
        else
      if (ansr[i]<=n && ansl[i]<=L[ansr[i]]) {
        ansr[i]++;
      }
        else break;
    }
  }
  
  cin>>q;
  while (q--) {
    cin>>x>>y;
    if (ansl[x]<=y && y<=ansr[x])
      cout<<"YES\n";
        else
      cout<<"NO\n";
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 24428 KB Output is correct
2 Correct 18 ms 24576 KB Output is correct
3 Correct 19 ms 24824 KB Output is correct
4 Correct 18 ms 24300 KB Output is correct
5 Correct 17 ms 24428 KB Output is correct
6 Correct 17 ms 24428 KB Output is correct
7 Correct 17 ms 24320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 24428 KB Output is correct
2 Correct 18 ms 24576 KB Output is correct
3 Correct 19 ms 24824 KB Output is correct
4 Correct 18 ms 24300 KB Output is correct
5 Correct 17 ms 24428 KB Output is correct
6 Correct 17 ms 24428 KB Output is correct
7 Correct 17 ms 24320 KB Output is correct
8 Correct 123 ms 30316 KB Output is correct
9 Correct 130 ms 30316 KB Output is correct
10 Correct 125 ms 30700 KB Output is correct
11 Correct 132 ms 31356 KB Output is correct
12 Correct 115 ms 29932 KB Output is correct
13 Correct 120 ms 30444 KB Output is correct
14 Correct 121 ms 30444 KB Output is correct
15 Correct 130 ms 30508 KB Output is correct
16 Correct 130 ms 30316 KB Output is correct
17 Correct 121 ms 30316 KB Output is correct
18 Correct 131 ms 30444 KB Output is correct
19 Correct 122 ms 30572 KB Output is correct
20 Correct 120 ms 30444 KB Output is correct
21 Correct 117 ms 30316 KB Output is correct
22 Correct 123 ms 30316 KB Output is correct
23 Correct 123 ms 30188 KB Output is correct
24 Correct 126 ms 30188 KB Output is correct
25 Correct 121 ms 30060 KB Output is correct
26 Correct 136 ms 30060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 65516 KB Output is correct
2 Correct 360 ms 64492 KB Output is correct
3 Correct 346 ms 62956 KB Output is correct
4 Correct 369 ms 65004 KB Output is correct
5 Correct 364 ms 65004 KB Output is correct
6 Correct 233 ms 52620 KB Output is correct
7 Correct 230 ms 52716 KB Output is correct
8 Correct 233 ms 52716 KB Output is correct
9 Correct 230 ms 52844 KB Output is correct
10 Correct 245 ms 52972 KB Output is correct
11 Correct 230 ms 52748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 24428 KB Output is correct
2 Correct 18 ms 24576 KB Output is correct
3 Correct 19 ms 24824 KB Output is correct
4 Correct 18 ms 24300 KB Output is correct
5 Correct 17 ms 24428 KB Output is correct
6 Correct 17 ms 24428 KB Output is correct
7 Correct 17 ms 24320 KB Output is correct
8 Correct 123 ms 30316 KB Output is correct
9 Correct 130 ms 30316 KB Output is correct
10 Correct 125 ms 30700 KB Output is correct
11 Correct 132 ms 31356 KB Output is correct
12 Correct 115 ms 29932 KB Output is correct
13 Correct 120 ms 30444 KB Output is correct
14 Correct 121 ms 30444 KB Output is correct
15 Correct 130 ms 30508 KB Output is correct
16 Correct 130 ms 30316 KB Output is correct
17 Correct 121 ms 30316 KB Output is correct
18 Correct 131 ms 30444 KB Output is correct
19 Correct 122 ms 30572 KB Output is correct
20 Correct 120 ms 30444 KB Output is correct
21 Correct 117 ms 30316 KB Output is correct
22 Correct 123 ms 30316 KB Output is correct
23 Correct 123 ms 30188 KB Output is correct
24 Correct 126 ms 30188 KB Output is correct
25 Correct 121 ms 30060 KB Output is correct
26 Correct 136 ms 30060 KB Output is correct
27 Correct 377 ms 65516 KB Output is correct
28 Correct 360 ms 64492 KB Output is correct
29 Correct 346 ms 62956 KB Output is correct
30 Correct 369 ms 65004 KB Output is correct
31 Correct 364 ms 65004 KB Output is correct
32 Correct 233 ms 52620 KB Output is correct
33 Correct 230 ms 52716 KB Output is correct
34 Correct 233 ms 52716 KB Output is correct
35 Correct 230 ms 52844 KB Output is correct
36 Correct 245 ms 52972 KB Output is correct
37 Correct 230 ms 52748 KB Output is correct
38 Correct 846 ms 107628 KB Output is correct
39 Correct 712 ms 119148 KB Output is correct
40 Correct 659 ms 94700 KB Output is correct
41 Correct 479 ms 117540 KB Output is correct
42 Correct 248 ms 52460 KB Output is correct
43 Correct 261 ms 53612 KB Output is correct
44 Correct 404 ms 77292 KB Output is correct
45 Correct 407 ms 77724 KB Output is correct
46 Correct 409 ms 78184 KB Output is correct
47 Correct 252 ms 54420 KB Output is correct
48 Correct 270 ms 53996 KB Output is correct
49 Correct 429 ms 78060 KB Output is correct
50 Correct 410 ms 78188 KB Output is correct
51 Correct 408 ms 78316 KB Output is correct
52 Correct 260 ms 69356 KB Output is correct
53 Correct 343 ms 89452 KB Output is correct
54 Correct 376 ms 105580 KB Output is correct
55 Correct 325 ms 87660 KB Output is correct