Submission #1037530

# Submission time Handle Problem Language Result Execution time Memory
1037530 2024-07-29T03:17:22 Z juicy Long Mansion (JOI17_long_mansion) C++17
100 / 100
208 ms 52308 KB
#include <bits/stdc++.h>

using namespace std;

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

const int N = 5e5 + 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;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23128 KB Output is correct
2 Correct 4 ms 23132 KB Output is correct
3 Correct 5 ms 23388 KB Output is correct
4 Correct 4 ms 23132 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23128 KB Output is correct
2 Correct 4 ms 23132 KB Output is correct
3 Correct 5 ms 23388 KB Output is correct
4 Correct 4 ms 23132 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 62 ms 24660 KB Output is correct
9 Correct 64 ms 24660 KB Output is correct
10 Correct 65 ms 24800 KB Output is correct
11 Correct 62 ms 24916 KB Output is correct
12 Correct 56 ms 24912 KB Output is correct
13 Correct 60 ms 24912 KB Output is correct
14 Correct 59 ms 24916 KB Output is correct
15 Correct 60 ms 24880 KB Output is correct
16 Correct 59 ms 25140 KB Output is correct
17 Correct 59 ms 24912 KB Output is correct
18 Correct 63 ms 24916 KB Output is correct
19 Correct 59 ms 24916 KB Output is correct
20 Correct 72 ms 25172 KB Output is correct
21 Correct 65 ms 25096 KB Output is correct
22 Correct 59 ms 24932 KB Output is correct
23 Correct 62 ms 24656 KB Output is correct
24 Correct 68 ms 24660 KB Output is correct
25 Correct 64 ms 24656 KB Output is correct
26 Correct 61 ms 24660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 28036 KB Output is correct
2 Correct 108 ms 28244 KB Output is correct
3 Correct 119 ms 27984 KB Output is correct
4 Correct 104 ms 27988 KB Output is correct
5 Correct 108 ms 28044 KB Output is correct
6 Correct 89 ms 27988 KB Output is correct
7 Correct 108 ms 28244 KB Output is correct
8 Correct 86 ms 28264 KB Output is correct
9 Correct 85 ms 28148 KB Output is correct
10 Correct 86 ms 28156 KB Output is correct
11 Correct 84 ms 28324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23128 KB Output is correct
2 Correct 4 ms 23132 KB Output is correct
3 Correct 5 ms 23388 KB Output is correct
4 Correct 4 ms 23132 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 4 ms 23132 KB Output is correct
8 Correct 62 ms 24660 KB Output is correct
9 Correct 64 ms 24660 KB Output is correct
10 Correct 65 ms 24800 KB Output is correct
11 Correct 62 ms 24916 KB Output is correct
12 Correct 56 ms 24912 KB Output is correct
13 Correct 60 ms 24912 KB Output is correct
14 Correct 59 ms 24916 KB Output is correct
15 Correct 60 ms 24880 KB Output is correct
16 Correct 59 ms 25140 KB Output is correct
17 Correct 59 ms 24912 KB Output is correct
18 Correct 63 ms 24916 KB Output is correct
19 Correct 59 ms 24916 KB Output is correct
20 Correct 72 ms 25172 KB Output is correct
21 Correct 65 ms 25096 KB Output is correct
22 Correct 59 ms 24932 KB Output is correct
23 Correct 62 ms 24656 KB Output is correct
24 Correct 68 ms 24660 KB Output is correct
25 Correct 64 ms 24656 KB Output is correct
26 Correct 61 ms 24660 KB Output is correct
27 Correct 103 ms 28036 KB Output is correct
28 Correct 108 ms 28244 KB Output is correct
29 Correct 119 ms 27984 KB Output is correct
30 Correct 104 ms 27988 KB Output is correct
31 Correct 108 ms 28044 KB Output is correct
32 Correct 89 ms 27988 KB Output is correct
33 Correct 108 ms 28244 KB Output is correct
34 Correct 86 ms 28264 KB Output is correct
35 Correct 85 ms 28148 KB Output is correct
36 Correct 86 ms 28156 KB Output is correct
37 Correct 84 ms 28324 KB Output is correct
38 Correct 158 ms 46932 KB Output is correct
39 Correct 208 ms 52308 KB Output is correct
40 Correct 140 ms 44628 KB Output is correct
41 Correct 201 ms 50772 KB Output is correct
42 Correct 92 ms 35412 KB Output is correct
43 Correct 92 ms 35408 KB Output is correct
44 Correct 120 ms 41044 KB Output is correct
45 Correct 133 ms 41180 KB Output is correct
46 Correct 130 ms 41556 KB Output is correct
47 Correct 95 ms 35412 KB Output is correct
48 Correct 121 ms 35316 KB Output is correct
49 Correct 129 ms 41292 KB Output is correct
50 Correct 134 ms 41232 KB Output is correct
51 Correct 125 ms 41556 KB Output is correct
52 Correct 117 ms 40216 KB Output is correct
53 Correct 165 ms 45048 KB Output is correct
54 Correct 157 ms 49928 KB Output is correct
55 Correct 142 ms 45140 KB Output is correct