답안 #1037529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037529 2024-07-29T03:16:49 Z juicy Long Mansion (JOI17_long_mansion) C++17
25 / 100
129 ms 21292 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 2e5 + 5;

int n, q;
int c[N], lt[N], rt[N], lst[N], mi[N], ma[N];
vector<int> key[N];

void dc(int l, int r) {
  if (l == r) {
    mi[l] = ma[l] = l;
    return;
  }
  int md = (l + r) / 2;
  dc(l, md), dc(md + 1, r);
  auto expand = [&](int &L, int &R) {
    bool chg = 1;
    while (chg) {
      chg = 0;
      if (L - 1 >= l && rt[L - 1] <= R) {
        --L;
        chg = 1;
      } 
      if (R < r && lt[R] >= L) {
        ++R;
        chg = 1;
      }
    }
  };
  int L = md + 1, R = md + 1;
  for (int i = md + 1; i <= r; ++i) {
    if (mi[i] == md + 1) {
      R = max(R, ma[i]);
      expand(L, R);
      mi[i] = L, ma[i] = R;
    }
  }
  L = md, R = md;
  for (int i = md; i >= l; --i) {
    if (ma[i] == md) {
      L = min(L, mi[i]);
      expand(L, R);
      mi[i] = L, ma[i] = R;
    }
  }
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n;
  for (int i = 1; i < n; ++i) {
    cin >> c[i];
  }  
  for (int i = 1; i <= n; ++i) {
    int b; cin >> b;
    key[i].resize(b);
    for (int &x : key[i]) {
      cin >> x;
      lst[x] = i;
    }
    lt[i] = lst[c[i]];
  }
  fill(lst, lst + n + 1, n + 1);
  for (int i = n; i > 0; --i) {
    rt[i] = lst[c[i]];
    for (int x : key[i]) {
      lst[x] = i;
    }
  }
  dc(1, n);
  cin >> q;
  while (q--) {
    int x, y; cin >> x >> y;
    cout << (mi[x] <= y && y <= ma[x] ? "YES" : "NO") << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8792 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8792 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 63 ms 14656 KB Output is correct
9 Correct 62 ms 14584 KB Output is correct
10 Correct 76 ms 15136 KB Output is correct
11 Correct 67 ms 15372 KB Output is correct
12 Correct 60 ms 14328 KB Output is correct
13 Correct 60 ms 14932 KB Output is correct
14 Correct 61 ms 14788 KB Output is correct
15 Correct 60 ms 14960 KB Output is correct
16 Correct 56 ms 14820 KB Output is correct
17 Correct 59 ms 14968 KB Output is correct
18 Correct 63 ms 14956 KB Output is correct
19 Correct 59 ms 14928 KB Output is correct
20 Correct 59 ms 14960 KB Output is correct
21 Correct 56 ms 14676 KB Output is correct
22 Correct 61 ms 14672 KB Output is correct
23 Correct 65 ms 14676 KB Output is correct
24 Correct 61 ms 14672 KB Output is correct
25 Correct 61 ms 14676 KB Output is correct
26 Correct 61 ms 14780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 21292 KB Output is correct
2 Correct 129 ms 21120 KB Output is correct
3 Correct 103 ms 21076 KB Output is correct
4 Correct 105 ms 21200 KB Output is correct
5 Correct 104 ms 21212 KB Output is correct
6 Correct 101 ms 20564 KB Output is correct
7 Correct 86 ms 20308 KB Output is correct
8 Correct 86 ms 20188 KB Output is correct
9 Correct 87 ms 20304 KB Output is correct
10 Correct 89 ms 20216 KB Output is correct
11 Correct 84 ms 20156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8792 KB Output is correct
2 Correct 3 ms 8796 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 63 ms 14656 KB Output is correct
9 Correct 62 ms 14584 KB Output is correct
10 Correct 76 ms 15136 KB Output is correct
11 Correct 67 ms 15372 KB Output is correct
12 Correct 60 ms 14328 KB Output is correct
13 Correct 60 ms 14932 KB Output is correct
14 Correct 61 ms 14788 KB Output is correct
15 Correct 60 ms 14960 KB Output is correct
16 Correct 56 ms 14820 KB Output is correct
17 Correct 59 ms 14968 KB Output is correct
18 Correct 63 ms 14956 KB Output is correct
19 Correct 59 ms 14928 KB Output is correct
20 Correct 59 ms 14960 KB Output is correct
21 Correct 56 ms 14676 KB Output is correct
22 Correct 61 ms 14672 KB Output is correct
23 Correct 65 ms 14676 KB Output is correct
24 Correct 61 ms 14672 KB Output is correct
25 Correct 61 ms 14676 KB Output is correct
26 Correct 61 ms 14780 KB Output is correct
27 Correct 105 ms 21292 KB Output is correct
28 Correct 129 ms 21120 KB Output is correct
29 Correct 103 ms 21076 KB Output is correct
30 Correct 105 ms 21200 KB Output is correct
31 Correct 104 ms 21212 KB Output is correct
32 Correct 101 ms 20564 KB Output is correct
33 Correct 86 ms 20308 KB Output is correct
34 Correct 86 ms 20188 KB Output is correct
35 Correct 87 ms 20304 KB Output is correct
36 Correct 89 ms 20216 KB Output is correct
37 Correct 84 ms 20156 KB Output is correct
38 Incorrect 27 ms 12592 KB Output isn't correct
39 Halted 0 ms 0 KB -