Submission #850516

# Submission time Handle Problem Language Result Execution time Memory
850516 2023-09-16T19:07:28 Z MilosMilutinovic Long Mansion (JOI17_long_mansion) C++14
10 / 100
3000 ms 28752 KB
/**
 *    author:  wxhtzdy
 *    created: 16.09.2023 20:57:23
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n;
  cin >> n;
  vector<int> c(n);
  for (int i = 0; i + 1 < n; i++) {
    cin >> c[i];
    --c[i];
  }
  vector<set<int>> pos(n);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      --a;
      pos[a].insert(i);
    }
  }
  auto Have = [&](int L, int R, int k) {
    auto it = pos[k].lower_bound(L);
    return (it != pos[k].end() && *it <= R);    
  };    
  vector<int> L(n), R(n);
  for (int i = 0; i < n; i++) {
    L[i] = R[i] = i;
    while (true) {
      if (L[i] > 0 && Have(L[i], R[i], c[L[i] - 1])) {
        L[i] = L[L[i] - 1];
        R[i] = max(R[i], R[L[i]]);
      } else if (R[i] + 1 < n && Have(L[i], R[i], c[R[i]])) {
        R[i] += 1;        
      } else {
        break;
      }
    }    
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    cout << (L[x] <= y && y <= R[x] ? "YES" : "NO") << '\n';
  }                  
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 17 ms 720 KB Output is correct
3 Correct 123 ms 860 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 816 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 17 ms 720 KB Output is correct
3 Correct 123 ms 860 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 816 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 736 KB Output is correct
8 Correct 79 ms 6592 KB Output is correct
9 Correct 74 ms 6484 KB Output is correct
10 Correct 88 ms 6840 KB Output is correct
11 Correct 163 ms 7484 KB Output is correct
12 Correct 75 ms 6224 KB Output is correct
13 Correct 71 ms 6772 KB Output is correct
14 Correct 70 ms 6832 KB Output is correct
15 Correct 79 ms 6796 KB Output is correct
16 Correct 68 ms 6652 KB Output is correct
17 Correct 77 ms 6860 KB Output is correct
18 Correct 71 ms 6740 KB Output is correct
19 Correct 71 ms 6736 KB Output is correct
20 Correct 80 ms 6636 KB Output is correct
21 Correct 69 ms 6480 KB Output is correct
22 Correct 72 ms 6616 KB Output is correct
23 Correct 72 ms 6512 KB Output is correct
24 Correct 77 ms 6432 KB Output is correct
25 Correct 74 ms 6504 KB Output is correct
26 Correct 72 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3083 ms 28752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 17 ms 720 KB Output is correct
3 Correct 123 ms 860 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 816 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 736 KB Output is correct
8 Correct 79 ms 6592 KB Output is correct
9 Correct 74 ms 6484 KB Output is correct
10 Correct 88 ms 6840 KB Output is correct
11 Correct 163 ms 7484 KB Output is correct
12 Correct 75 ms 6224 KB Output is correct
13 Correct 71 ms 6772 KB Output is correct
14 Correct 70 ms 6832 KB Output is correct
15 Correct 79 ms 6796 KB Output is correct
16 Correct 68 ms 6652 KB Output is correct
17 Correct 77 ms 6860 KB Output is correct
18 Correct 71 ms 6740 KB Output is correct
19 Correct 71 ms 6736 KB Output is correct
20 Correct 80 ms 6636 KB Output is correct
21 Correct 69 ms 6480 KB Output is correct
22 Correct 72 ms 6616 KB Output is correct
23 Correct 72 ms 6512 KB Output is correct
24 Correct 77 ms 6432 KB Output is correct
25 Correct 74 ms 6504 KB Output is correct
26 Correct 72 ms 6484 KB Output is correct
27 Execution timed out 3083 ms 28752 KB Time limit exceeded
28 Halted 0 ms 0 KB -