답안 #1037541

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

using namespace std;

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

const int N = 5e5 + 5, LG = 19;

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

void expand(int i) {
  for (int j = LG - 1; ~j; --j) {
    if (ma[i] + (1 << j) <= n && spt[j][ma[i]] >= mi[i]) {
      ma[i] += 1 << j;
    }
  }
}

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;
    }
  }
  for (int i = 2; i <= n; ++i) {
    lg[i] = lg[i / 2] + 1;
  }
  for (int i = 1; i <= n; ++i) {
    spt[0][i] = lt[i];
  }
  for (int j = 1; j <= lg[n]; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
      spt[j][i] = min(spt[j - 1][i], spt[j - 1][i + (1 << j - 1)]);
    } 
  }
  vector<int> st;
  for (int i = 1; i <= n; ++i) {
    mi[i] = ma[i] = i;
    expand(i);
    while (st.size() && rt[st.back()] <= ma[i]) {
      mi[i] = min(mi[i], mi[st.back()]);
      ma[i] = max(ma[i], ma[st.back()]);
      expand(i);
      st.pop_back();
    }
    st.push_back(i);
  }
  cin >> q;
  while (q--) {
    int x, y; cin >> x >> y;
    cout << (mi[x] <= y && y <= ma[x] ? "YES" : "NO") << "\n";
  }
  return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:56:61: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   56 |       spt[j][i] = min(spt[j - 1][i], spt[j - 1][i + (1 << j - 1)]);
      |                                                           ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 47708 KB Output is correct
2 Correct 7 ms 49756 KB Output is correct
3 Correct 8 ms 52060 KB Output is correct
4 Correct 6 ms 47708 KB Output is correct
5 Correct 6 ms 47704 KB Output is correct
6 Correct 7 ms 47708 KB Output is correct
7 Correct 6 ms 47704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 47708 KB Output is correct
2 Correct 7 ms 49756 KB Output is correct
3 Correct 8 ms 52060 KB Output is correct
4 Correct 6 ms 47708 KB Output is correct
5 Correct 6 ms 47704 KB Output is correct
6 Correct 7 ms 47708 KB Output is correct
7 Correct 6 ms 47704 KB Output is correct
8 Correct 67 ms 49360 KB Output is correct
9 Correct 66 ms 49332 KB Output is correct
10 Correct 68 ms 51792 KB Output is correct
11 Correct 70 ms 53708 KB Output is correct
12 Correct 67 ms 47496 KB Output is correct
13 Correct 65 ms 49608 KB Output is correct
14 Correct 62 ms 49484 KB Output is correct
15 Correct 64 ms 49616 KB Output is correct
16 Correct 62 ms 49768 KB Output is correct
17 Correct 63 ms 49416 KB Output is correct
18 Correct 61 ms 49560 KB Output is correct
19 Correct 60 ms 49492 KB Output is correct
20 Correct 57 ms 49748 KB Output is correct
21 Correct 60 ms 49804 KB Output is correct
22 Correct 55 ms 49616 KB Output is correct
23 Correct 63 ms 49488 KB Output is correct
24 Correct 74 ms 49484 KB Output is correct
25 Correct 65 ms 49492 KB Output is correct
26 Correct 69 ms 49236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 62800 KB Output is correct
2 Correct 111 ms 62800 KB Output is correct
3 Correct 111 ms 62804 KB Output is correct
4 Correct 112 ms 62920 KB Output is correct
5 Correct 115 ms 62776 KB Output is correct
6 Correct 94 ms 62808 KB Output is correct
7 Correct 92 ms 63056 KB Output is correct
8 Correct 114 ms 63056 KB Output is correct
9 Correct 101 ms 62968 KB Output is correct
10 Correct 92 ms 63052 KB Output is correct
11 Correct 103 ms 63056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 47708 KB Output is correct
2 Correct 7 ms 49756 KB Output is correct
3 Correct 8 ms 52060 KB Output is correct
4 Correct 6 ms 47708 KB Output is correct
5 Correct 6 ms 47704 KB Output is correct
6 Correct 7 ms 47708 KB Output is correct
7 Correct 6 ms 47704 KB Output is correct
8 Correct 67 ms 49360 KB Output is correct
9 Correct 66 ms 49332 KB Output is correct
10 Correct 68 ms 51792 KB Output is correct
11 Correct 70 ms 53708 KB Output is correct
12 Correct 67 ms 47496 KB Output is correct
13 Correct 65 ms 49608 KB Output is correct
14 Correct 62 ms 49484 KB Output is correct
15 Correct 64 ms 49616 KB Output is correct
16 Correct 62 ms 49768 KB Output is correct
17 Correct 63 ms 49416 KB Output is correct
18 Correct 61 ms 49560 KB Output is correct
19 Correct 60 ms 49492 KB Output is correct
20 Correct 57 ms 49748 KB Output is correct
21 Correct 60 ms 49804 KB Output is correct
22 Correct 55 ms 49616 KB Output is correct
23 Correct 63 ms 49488 KB Output is correct
24 Correct 74 ms 49484 KB Output is correct
25 Correct 65 ms 49492 KB Output is correct
26 Correct 69 ms 49236 KB Output is correct
27 Correct 107 ms 62800 KB Output is correct
28 Correct 111 ms 62800 KB Output is correct
29 Correct 111 ms 62804 KB Output is correct
30 Correct 112 ms 62920 KB Output is correct
31 Correct 115 ms 62776 KB Output is correct
32 Correct 94 ms 62808 KB Output is correct
33 Correct 92 ms 63056 KB Output is correct
34 Correct 114 ms 63056 KB Output is correct
35 Correct 101 ms 62968 KB Output is correct
36 Correct 92 ms 63052 KB Output is correct
37 Correct 103 ms 63056 KB Output is correct
38 Correct 164 ms 78328 KB Output is correct
39 Correct 171 ms 82100 KB Output is correct
40 Correct 148 ms 74492 KB Output is correct
41 Correct 181 ms 80468 KB Output is correct
42 Correct 97 ms 63060 KB Output is correct
43 Correct 95 ms 62800 KB Output is correct
44 Correct 142 ms 68144 KB Output is correct
45 Correct 138 ms 68068 KB Output is correct
46 Correct 129 ms 67928 KB Output is correct
47 Correct 98 ms 62800 KB Output is correct
48 Correct 94 ms 62804 KB Output is correct
49 Correct 127 ms 67920 KB Output is correct
50 Correct 137 ms 67924 KB Output is correct
51 Correct 137 ms 67924 KB Output is correct
52 Correct 118 ms 68300 KB Output is correct
53 Correct 153 ms 73680 KB Output is correct
54 Correct 166 ms 77508 KB Output is correct
55 Correct 160 ms 73676 KB Output is correct