Editorial for Xếp Gạch


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define print_op(...) ostream &operator<<(ostream &out, const __VA_ARGS__ &u)
#define db(val) "[" #val " = " << (val) << "] "
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#ifdef LOCAL
#define clog cerr << setw(__db_level * 2) << setfill(' ') << "" << setw(0)
#define DB() debug_block CONCAT(dbbl, __LINE__)
int __db_level = 0;
struct debug_block
{
  debug_block()
  {
    clog << "{" << endl;
    ++__db_level;
  }
  ~debug_block()
  {
    --__db_level;
    clog << "}" << endl;
  }
};
#else
#define clog \
  if (0)     \
  cerr
#define DB(...)
#endif
template <class U, class V>
print_op(pair<U, V>)
{
  return out << "(" << u.first << ", " << u.second << ")";
}
template <class Con, class = decltype(begin(declval<Con>()))>
typename enable_if<!is_same<Con, string>::value, ostream &>::type
operator<<(ostream &out, const Con &con)
{
  out << "{";
  for (auto beg = con.begin(), it = beg; it != con.end(); ++it)
    out << (it == beg ? "" : ", ") << *it;
  return out << "}";
}
template <size_t i, class T>
ostream &print_tuple_utils(ostream &out, const T &tup)
{
  if constexpr (i == tuple_size<T>::value)
    return out << ")";
  else
    return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup);
}
template <class... U>
print_op(tuple<U...>)
{
  return print_tuple_utils<0, tuple<U...>>(out, u);
}
template <typename A, typename B>
bool maximize(A &a, B b)
{
  return a < b ? a = b, true : false;
}
template <typename A, typename B>
bool minimize(A &a, B b)
{
  return a > b ? a = b, true : false;
}


void solve()
{
    int n, q;
    int m, k, l;
    vector<int> a, b, c;
  cin >> n >> q;
  cin >> m;
  for (int i = 1; i <= m; ++i)
  {
    int x;
    cin >> x;
    a.push_back(x);
  }
  cin >> k;
  for (int i = 1; i <= k; ++i)
  {
    int x;
    cin >> x;
    b.push_back(x);
  }
  cin >> l;
  for (int i = 1; i <= l; ++i)
  {
    int x;
    cin >> x;
    c.push_back(x);
  }
  int mm = m - 1, kk = k - 1, ll = l - 1;
  set<tuple<int, int, int>> sol = {{mm, kk, ll}};
  while (mm >= 0 || kk >= 0 || ll >= 0)
  {
    if (mm >= 0 && kk >= 0 && a[mm] == b[kk])
    {
      --mm;
      --kk;
      sol.insert({mm, kk, ll});
    }
    else if (mm >= 0 && ll >= 0 && a[mm] == c[ll])
    {
      --mm;
      --ll;
      sol.insert({mm, kk, ll});
    }
    else if (kk >= 0 && ll >= 0 && b[kk] == c[ll])
    {
      --kk;
      --ll;
      sol.insert({mm, kk, ll});
    }
    else
      break;
  }
  clog << db(sol) << endl;

  for (int i = 0; i < q; ++i)
  {
    int x, y, z;
    cin >> x >> y >> z;
    clog << db(x) << db(y) << db(z) << endl;
    x = x - 1;
    y = y - 1;
    z = z - 1;
    if (sol.count({x, y, z}))
      cout << "MofK\n";
    else
      cout << "Lihwy\n";
  }
}

int main()
{
  cin.tie(0)->sync_with_stdio(0);
#ifdef LOCAL
  freopen("main.inp", "r", stdin);
  freopen("main.out", "w", stdout);
#endif
  int tt;
  cin >> tt;
  while (tt--)
    solve();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.