제출 #1254974

#제출 시각아이디문제언어결과실행 시간메모리
1254974flashmt장애물 (IOI25_obstacles)C++20
24 / 100
136 ms30716 KiB
#include "obstacles.h"
#include <bits/stdc++.h>
#ifdef LOCAL
#include "Debug.h"
#else
#define debug(...) 42
#endif
using namespace std;

template<typename T>
struct SparseTable
{
  int n;
  vector<vector<T>> mat;

  SparseTable(const vector<T>& a)
  {
    n = int(a.size());
    int maxLog = 32 - __builtin_clz(n);
    mat.resize(maxLog);
    mat[0] = a;
    for (int j = 1; j < maxLog; j++)
    {
      mat[j].resize(n - (1 << j) + 1);
      for (int i = 0; i <= n - (1 << j); i++)
        mat[j][i] = max(mat[j - 1][i], mat[j - 1][i + (1 << (j - 1))]);
    }
  }

  T get(int from, int to)
  {
    if (from > to)
      return -1;
    assert(0 <= from && from <= to && to <= n - 1);
    int lg = 31 - __builtin_clz(to - from + 1);
    return max(mat[lg][from], mat[lg][to - (1 << lg) + 1]);
  }
};

int n, m;
vector<int> t, h;
int isSub2;
SparseTable<int> *st;
set<int> atH[3];

void initialize(vector<int> _t, vector<int> _h) {
  t = _t; h = _h;
  n = size(t); m = size(h);
  isSub2 = 1;
  for (int i = 0; i + 1 < n; i++)
    if (t[i] > t[i + 1])
      isSub2 = 0;

  st = new SparseTable(h);

  for (int i = 0; i < m; i++)
    if (h[i] < 3)
      atH[h[i]].insert(i);
  for (int i = 0; i < 3; i++)
  {
    atH[i].insert(-1);
    atH[i].insert(m);
  }
}

bool can_reach(int l, int r, int from, int to) {
  if (from > to)
    swap(from, to);

  if (from + 1 == to)
    return 1;

  int maxH = st->get(from, to);

  if (isSub2)
    return maxH < t[n - 1];

  if (t == vector{2, 1, 3})
  {
    if (maxH < 2)
      return 1;
    if (maxH >= 3)
      return 0;

    int l0 = *prev(atH[0].upper_bound(from));
    if (l0 < 0 || st->get(l0 + 1, from) >= 2)
      return 0;
    int r0 = *atH[0].lower_bound(to);
    if (r0 == m || st->get(to, r0 - 1) >= 2)
      return 0;
    return 1;
  }

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...