#include #define FASTIO using namespace std; using ll = long long; using Vi = std::vector; using Vl = std::vector; using Pii = std::pair; using Pll = std::pair; constexpr int I_INF = std::numeric_limits::max(); constexpr ll L_INF = std::numeric_limits::max(); template inline bool chmin(T1& a, const T2& b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T1& a, const T2& b) { if (a < b) { a = b; return true; } return false; } template class Prints { private: class __Prints { public: __Prints(const char* sep, const char* term) : sep(sep), term(term) {} template #if __cplusplus >= 201703L auto operator()(const Args&... args) const -> decltype((os << ... << std::declval()), void()) { #else void operator()(const Args&... args) const { #endif print(args...); } template #if __cplusplus >= 201703L auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval()[0])>(), void()) { #else void pvec(const T& vec, size_t sz) const { #endif for (size_t i = 0; i < sz; i++) os << vec[i] << (i == sz - 1 ? term : sep); } template #if __cplusplus >= 201703L auto pmat(const T& mat, size_t h, size_t w) const -> decltype(os << std::declval()[0][0])>(), void()) { #else void pmat(const T& mat, size_t h, size_t w) const { #endif for (size_t i = 0; i < h; i++) for (size_t j = 0; j < w; j++) os << mat[i][j] << (j == w - 1 ? term : sep); } private: const char *sep, *term; void print() const { os << term; } void print_rest() const { os << term; } template void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); } template void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); } }; public: Prints() {} __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); } }; Prints<> prints; Prints prints_err; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% template class SegmentTree { private: const int n; const Op op; const T id; std::vector vec; int sz; public: explicit SegmentTree(int n, Op op, T id) noexcept : n(n), op(op), id(id) { sz = 1; while (sz < n) sz <<= 1; vec.assign(sz << 1, id); } explicit SegmentTree(const std::vector& vec, Op op, T id) noexcept : n(vec.size()), op(op), id(id) { sz = 1; while (sz < n) sz <<= 1; this->vec.assign(sz << 1, id); set_array(vec); } T& operator[](int idx) noexcept { return vec[idx + sz]; } void set_value(int idx, T val) noexcept { vec[idx + sz] = val; } template void set_array(RandomIt _begin, RandomIt _end) noexcept { std::copy(_begin, _end, vec.begin() + sz); } template void set_array(const Vec& v) noexcept { set_array(std::begin(v), std::end(v)); } void build() noexcept { for (int i = sz - 1; i > 0; i--) { vec[i] = op(vec[i << 1], vec[(i << 1) | 1]); } } void update(int idx, T val) noexcept { idx += sz; vec[idx] = val; for (idx >>= 1; idx > 0; idx >>= 1) { vec[idx] = op(vec[idx << 1], vec[(idx << 1) | 1]); } } T query(int l, int r) const noexcept { T l_val = id, r_val = id; l += sz, r += sz - 1; for (; l <= r; l >>= 1, r >>= 1) { if (l & 1) l_val = op(l_val, vec[l++]); if (!(r & 1)) r_val = op(vec[r--], r_val); } return op(l_val, r_val); } T query_all() const noexcept { return query(0, sz); } // Return the largest x such that check(A[idx] op ... op A[x - 1]) == true // complexity: O(log (n)) template int max_right(int idx, const F& check) const noexcept { T acc = id; return idx < n ? _max_right(idx, check, acc, 1, 0, sz) : n; } // Return the smallest x such that check(A[x] op ... op A[idx - 1]) == true // complexity: O(log (n)) template int min_left(int idx, const F& check) const noexcept { T acc = id; return idx > 0 ? _min_left(idx, check, acc, 1, 0, sz) : 0; } void reset() noexcept { std::fill(vec.begin(), vec.end(), id); } private: template int _max_right(int idx, const F& check, T& acc, int k, int l, int r) const noexcept { if (l + 1 == r) { acc = op(acc, vec[k]); return check(acc) ? n : k - sz; } const int mid = (l + r) >> 1; if (mid <= idx) return _max_right(idx, check, acc, (k << 1) | 1, mid, r); if (idx <= l) { T tmp = op(acc, vec[k]); if (check(tmp)) { acc = tmp; return n; } } const int vl = _max_right(idx, check, acc, k << 1, l, mid); if (vl < n) return vl; return _max_right(idx, check, acc, (k << 1) | 1, mid, r); } template int _min_left(int idx, const F& check, T& acc, int k, int l, int r) const noexcept { if (l + 1 == r) { acc = op(acc, vec[k]); return check(acc) ? 0 : k - sz + 1; } const int mid = (l + r) >> 1; if (mid >= idx) return _min_left(idx, check, acc, k << 1, l, mid); if (idx >= r) { T tmp = op(acc, vec[k]); if (check(tmp)) { acc = tmp; return 0; } } const int vr = _min_left(idx, check, acc, (k << 1) | 1, mid, r); if (vr > 0) return vr; return _min_left(idx, check, acc, k << 1, l, mid); } }; void solve() { ll N, M, Q; cin >> N >> M >> Q; auto op = [&](const Vi& l, const Vi& r) -> Vi { Vi res(N); for (ll i = 0; i < N; i++) { res[i] = r[l[i]]; } return res; }; Vi e(N); iota(e.begin(), e.end(), 0); SegmentTree seg(M, op, e); while (Q--) { int type; cin >> type; if (type == 1) { int k; cin >> k; --k; Vi p(N); for (ll i = 0; i < N; i++) { cin >> p[i]; --p[i]; } seg.update(k, p); } else if (type == 2) { int k; cin >> k; Vi q = seg.query(0, k); Vi res(N); for (ll i = 0; i < N; i++) { res[q[i]] = i; } for (ll i = 0; i < N; i++) { cout << res[i] + 1 << " "; } prints()(); } else { int l, r; cin >> l >> r; --l; Vi q = seg.query(l, r); ll res = 0; for (ll i = 0; i < N; i++) { res += abs(i - q[i]); } prints()(res); } } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO std::cin.tie(nullptr), std::cout.tie(nullptr); std::ios::sync_with_stdio(false); #endif #ifdef FILEINPUT std::ifstream ifs("./in_out/input.txt"); std::cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT std::ofstream ofs("./in_out/output.txt"); std::cout.rdbuf(ofs.rdbuf()); #endif std::cout << std::setprecision(18) << std::fixed; solve(); std::cout << std::flush; return 0; }