답안 #24102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24102 2017-05-31T00:45:58 Z jiaqiyang Long Mansion (JOI17_long_mansion) C++14
100 / 100
276 ms 40184 KB
#include <cctype>
#include <cstdio>
#include <cstring>
#include <vector>

const int N = 500000 + 10;

int nextInt() {
  char ch;
  while (!isdigit(ch = getchar())) {}
  int res = ch - '0';
  while (isdigit(ch = getchar())) res = 10 * res + ch - '0';
  return res;
}

int n, c[N], left[N], right[N];

std::vector<int> a[N];

int pred[N], succ[N];

void init() {
  static int last[N];
  memset(last, 0, sizeof last);
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < a[i].size(); ++j) last[a[i][j]] = i;
    pred[i] = last[c[i]];
  }
  memset(last, 0, sizeof last);
  for (int i = n; i > 1; --i) {
    for (int j = 0; j < a[i].size(); ++j) last[a[i][j]] = i;
    succ[i - 1] = last[c[i - 1]];
  }
}

inline bool check(int l, int r, int x) {
  return (pred[x] && l <= pred[x] && pred[x] <= r) || (succ[x] && l <= succ[x] && succ[x] <= r);
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) c[i] = nextInt();
  for (int i = 1; i <= n; ++i)
    for (int b = nextInt(); b--;)
      a[i].push_back(nextInt());
  init();
  for (int i = 1; i <= n; ++i) {
    int &l = left[i] = i, &r = right[i] = i;
    while (1) {
      if (l > 1 && check(l, r, l - 1)) {
        r = std::max(r, right[l - 1]);
        l = left[l - 1];
        continue;
      }
      if (r < n && check(l, r, r)) {
        ++r;
        continue;
      }
      break;
    }
  }
  for (int q = nextInt(); q--;) {
    int x = nextInt(), y = nextInt();
    puts(left[x] <= y && y <= right[x] ? "YES" : "NO");
  }
  return 0;
}

Compilation message

long_mansion.cpp: In function 'void init()':
long_mansion.cpp:26:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < a[i].size(); ++j) last[a[i][j]] = i;
                       ^
long_mansion.cpp:31:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < a[i].size(); ++j) last[a[i][j]] = i;
                       ^
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24740 KB Output is correct
2 Correct 3 ms 24740 KB Output is correct
3 Correct 3 ms 24740 KB Output is correct
4 Correct 3 ms 24740 KB Output is correct
5 Correct 3 ms 24740 KB Output is correct
6 Correct 6 ms 24740 KB Output is correct
7 Correct 6 ms 24740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24740 KB Output is correct
2 Correct 3 ms 24740 KB Output is correct
3 Correct 3 ms 24740 KB Output is correct
4 Correct 3 ms 24740 KB Output is correct
5 Correct 3 ms 24740 KB Output is correct
6 Correct 6 ms 24740 KB Output is correct
7 Correct 6 ms 24740 KB Output is correct
8 Correct 56 ms 24740 KB Output is correct
9 Correct 66 ms 24740 KB Output is correct
10 Correct 73 ms 24740 KB Output is correct
11 Correct 83 ms 24740 KB Output is correct
12 Correct 59 ms 24608 KB Output is correct
13 Correct 79 ms 24740 KB Output is correct
14 Correct 73 ms 24740 KB Output is correct
15 Correct 66 ms 24740 KB Output is correct
16 Correct 63 ms 24740 KB Output is correct
17 Correct 69 ms 24740 KB Output is correct
18 Correct 83 ms 24740 KB Output is correct
19 Correct 66 ms 24740 KB Output is correct
20 Correct 59 ms 24740 KB Output is correct
21 Correct 69 ms 24740 KB Output is correct
22 Correct 63 ms 24740 KB Output is correct
23 Correct 46 ms 24740 KB Output is correct
24 Correct 63 ms 24740 KB Output is correct
25 Correct 66 ms 24740 KB Output is correct
26 Correct 49 ms 24740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 28568 KB Output is correct
2 Correct 173 ms 28436 KB Output is correct
3 Correct 176 ms 28304 KB Output is correct
4 Correct 173 ms 28436 KB Output is correct
5 Correct 136 ms 28436 KB Output is correct
6 Correct 106 ms 27776 KB Output is correct
7 Correct 103 ms 27776 KB Output is correct
8 Correct 119 ms 27776 KB Output is correct
9 Correct 123 ms 27776 KB Output is correct
10 Correct 76 ms 27776 KB Output is correct
11 Correct 133 ms 27776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 24740 KB Output is correct
2 Correct 3 ms 24740 KB Output is correct
3 Correct 3 ms 24740 KB Output is correct
4 Correct 3 ms 24740 KB Output is correct
5 Correct 3 ms 24740 KB Output is correct
6 Correct 6 ms 24740 KB Output is correct
7 Correct 6 ms 24740 KB Output is correct
8 Correct 56 ms 24740 KB Output is correct
9 Correct 66 ms 24740 KB Output is correct
10 Correct 73 ms 24740 KB Output is correct
11 Correct 83 ms 24740 KB Output is correct
12 Correct 59 ms 24608 KB Output is correct
13 Correct 79 ms 24740 KB Output is correct
14 Correct 73 ms 24740 KB Output is correct
15 Correct 66 ms 24740 KB Output is correct
16 Correct 63 ms 24740 KB Output is correct
17 Correct 69 ms 24740 KB Output is correct
18 Correct 83 ms 24740 KB Output is correct
19 Correct 66 ms 24740 KB Output is correct
20 Correct 59 ms 24740 KB Output is correct
21 Correct 69 ms 24740 KB Output is correct
22 Correct 63 ms 24740 KB Output is correct
23 Correct 46 ms 24740 KB Output is correct
24 Correct 63 ms 24740 KB Output is correct
25 Correct 66 ms 24740 KB Output is correct
26 Correct 49 ms 24740 KB Output is correct
27 Correct 169 ms 28568 KB Output is correct
28 Correct 173 ms 28436 KB Output is correct
29 Correct 176 ms 28304 KB Output is correct
30 Correct 173 ms 28436 KB Output is correct
31 Correct 136 ms 28436 KB Output is correct
32 Correct 106 ms 27776 KB Output is correct
33 Correct 103 ms 27776 KB Output is correct
34 Correct 119 ms 27776 KB Output is correct
35 Correct 123 ms 27776 KB Output is correct
36 Correct 76 ms 27776 KB Output is correct
37 Correct 133 ms 27776 KB Output is correct
38 Correct 276 ms 37148 KB Output is correct
39 Correct 193 ms 40184 KB Output is correct
40 Correct 199 ms 33980 KB Output is correct
41 Correct 246 ms 40184 KB Output is correct
42 Correct 116 ms 27776 KB Output is correct
43 Correct 133 ms 27776 KB Output is correct
44 Correct 196 ms 30812 KB Output is correct
45 Correct 146 ms 30812 KB Output is correct
46 Correct 149 ms 30812 KB Output is correct
47 Correct 103 ms 27776 KB Output is correct
48 Correct 129 ms 27776 KB Output is correct
49 Correct 159 ms 30812 KB Output is correct
50 Correct 219 ms 30812 KB Output is correct
51 Correct 186 ms 30812 KB Output is correct
52 Correct 149 ms 30812 KB Output is correct
53 Correct 209 ms 33980 KB Output is correct
54 Correct 196 ms 37148 KB Output is correct
55 Correct 189 ms 33980 KB Output is correct