답안 #682613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682613 2023-01-16T15:27:53 Z peijar Long Mansion (JOI17_long_mansion) C++17
25 / 100
3000 ms 42744 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

string to_string(string s) { return s; }
template <typename T> string to_string(T v) {
  bool first = true;
  string res = "[";
  for (const auto &x : v) {
    if (!first)
      res += ", ";
    first = false;
    res += to_string(x);
  }
  res += "]";
  return res;
}

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cout << ' ' << to_string(H);
  dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int nbChambres;
  cin >> nbChambres;
  vector<int> type(nbChambres - 1);
  for (int &t : type) {
    cin >> t;
    --t;
  }

  vector<vector<int>> posType(nbChambres);
  for (int i = 0; i < nbChambres; ++i) {
    int cnt;
    cin >> cnt;
    while (cnt--) {
      int t;
      cin >> t;
      --t;
      posType[t].push_back(i);
    }
  }
  vector<int> L(nbChambres), R(nbChambres);
  for (int iChambre = nbChambres - 1; iChambre >= 0; --iChambre) {
    int j = iChambre;
    while (j + 1 < nbChambres) {
      int t = type[j];
      auto fst = lower_bound(posType[t].begin(), posType[t].end(), iChambre) -
                 posType[t].begin();
      if (fst == (int)posType[t].size() or posType[t][fst] > j)
        break;
      j = R[j + 1];
    }
    R[iChambre] = j;
  }

  dbg(R);

  for (int iChambre = 0; iChambre < nbChambres; ++iChambre) {
    L[iChambre] = iChambre;
    while (L[iChambre] >= 0) {
      while (R[iChambre] + 1 < nbChambres) {
        int t = type[R[iChambre]];
        auto fst =
            lower_bound(posType[t].begin(), posType[t].end(), L[iChambre]) -
            posType[t].begin();
        if (fst == (int)posType[t].size() or posType[t][fst] > R[iChambre])
          break;
        R[iChambre] = R[R[iChambre] + 1];
      }
      if (L[iChambre] == 0)
        break;

      // can we reduce L[iChambre] ?
      int t = type[L[iChambre] - 1];
      auto fst =
          lower_bound(posType[t].begin(), posType[t].end(), L[iChambre]) -
          posType[t].begin();
      if (fst == (int)posType[t].size() or posType[t][fst] > R[iChambre])
        break;
      L[iChambre] = L[L[iChambre] - 1];
      R[iChambre] = max(R[iChambre], R[L[iChambre]]);
    }
  }

  dbg(L);
  dbg(R);

  int Q;
  cin >> Q;
  while (Q--) {
    int from, to;
    cin >> from >> to;
    --from, --to;
    cout << (L[from] <= to and to <= R[from] ? "YES" : "NO") << '\n';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 94 ms 6332 KB Output is correct
9 Correct 96 ms 6384 KB Output is correct
10 Correct 99 ms 6808 KB Output is correct
11 Correct 112 ms 7072 KB Output is correct
12 Correct 97 ms 5964 KB Output is correct
13 Correct 90 ms 6480 KB Output is correct
14 Correct 90 ms 6524 KB Output is correct
15 Correct 97 ms 6512 KB Output is correct
16 Correct 89 ms 6364 KB Output is correct
17 Correct 95 ms 6540 KB Output is correct
18 Correct 93 ms 6588 KB Output is correct
19 Correct 116 ms 6652 KB Output is correct
20 Correct 89 ms 6664 KB Output is correct
21 Correct 110 ms 6272 KB Output is correct
22 Correct 95 ms 6424 KB Output is correct
23 Correct 99 ms 6228 KB Output is correct
24 Correct 97 ms 6344 KB Output is correct
25 Correct 97 ms 6256 KB Output is correct
26 Correct 103 ms 6256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 192 ms 18344 KB Output is correct
2 Correct 183 ms 17484 KB Output is correct
3 Correct 168 ms 16984 KB Output is correct
4 Correct 191 ms 17844 KB Output is correct
5 Correct 186 ms 17900 KB Output is correct
6 Correct 167 ms 15504 KB Output is correct
7 Correct 142 ms 15316 KB Output is correct
8 Correct 138 ms 15436 KB Output is correct
9 Correct 151 ms 15320 KB Output is correct
10 Correct 138 ms 15448 KB Output is correct
11 Correct 141 ms 15268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 94 ms 6332 KB Output is correct
9 Correct 96 ms 6384 KB Output is correct
10 Correct 99 ms 6808 KB Output is correct
11 Correct 112 ms 7072 KB Output is correct
12 Correct 97 ms 5964 KB Output is correct
13 Correct 90 ms 6480 KB Output is correct
14 Correct 90 ms 6524 KB Output is correct
15 Correct 97 ms 6512 KB Output is correct
16 Correct 89 ms 6364 KB Output is correct
17 Correct 95 ms 6540 KB Output is correct
18 Correct 93 ms 6588 KB Output is correct
19 Correct 116 ms 6652 KB Output is correct
20 Correct 89 ms 6664 KB Output is correct
21 Correct 110 ms 6272 KB Output is correct
22 Correct 95 ms 6424 KB Output is correct
23 Correct 99 ms 6228 KB Output is correct
24 Correct 97 ms 6344 KB Output is correct
25 Correct 97 ms 6256 KB Output is correct
26 Correct 103 ms 6256 KB Output is correct
27 Correct 192 ms 18344 KB Output is correct
28 Correct 183 ms 17484 KB Output is correct
29 Correct 168 ms 16984 KB Output is correct
30 Correct 191 ms 17844 KB Output is correct
31 Correct 186 ms 17900 KB Output is correct
32 Correct 167 ms 15504 KB Output is correct
33 Correct 142 ms 15316 KB Output is correct
34 Correct 138 ms 15436 KB Output is correct
35 Correct 151 ms 15320 KB Output is correct
36 Correct 138 ms 15448 KB Output is correct
37 Correct 141 ms 15268 KB Output is correct
38 Correct 271 ms 38148 KB Output is correct
39 Correct 354 ms 42744 KB Output is correct
40 Correct 261 ms 32664 KB Output is correct
41 Correct 320 ms 39208 KB Output is correct
42 Correct 181 ms 16544 KB Output is correct
43 Correct 155 ms 16704 KB Output is correct
44 Correct 247 ms 26732 KB Output is correct
45 Correct 220 ms 26876 KB Output is correct
46 Correct 245 ms 26980 KB Output is correct
47 Correct 149 ms 16892 KB Output is correct
48 Correct 160 ms 16624 KB Output is correct
49 Correct 214 ms 26676 KB Output is correct
50 Correct 250 ms 26828 KB Output is correct
51 Correct 246 ms 27180 KB Output is correct
52 Execution timed out 3062 ms 19092 KB Time limit exceeded
53 Halted 0 ms 0 KB -