#include #include #define For(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rFor(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair pii; typedef pair pll; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } template struct coord_comp { vector v; bool sorted = false; coord_comp() {} int size() { return v.size(); } void add(T x) { v.push_back(x); } void build() { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); sorted = true; } int get_idx(T x) { assert(sorted); return lower_bound(v.begin(), v.end(), x) - v.begin(); } T &operator[](int i) { return v[i]; } }; constexpr lint mod = 1000000007; constexpr lint INF = mod * mod; constexpr int MAX = 100010; using namespace atcoder; int n, m, q; vector op(vector a, vector b) { rep(i, a.size()) a[i] = b[a[i]]; return a; } vector e() { vector ret(n, 0); iota(ret.begin(), ret.end(), 0); return ret; } int main() { scanf("%d%d%d", &n, &m, &q); segtree, op, e> st(vector>(m, e())); rep(_, q) { int t; scanf("%d", &t); if (t == 1) { int d; scanf("%d", &d); --d; vector tmp(n); rep(i, n) { scanf("%d", &tmp[i]); --tmp[i]; } st.set(d, tmp); } else if (t == 2) { int s; scanf("%d", &s); auto tmp = st.prod(0, s); vector ans(n); rep(i, n) ans[tmp[i]] = i; for (auto x : ans) printf("%d ", x + 1); printf("\n"); } else { int l, r; scanf("%d%d", &l, &r); --l; auto tmp = st.prod(l, r); int ans = 0; rep(i, n) ans += abs(i - tmp[i]); printf("%d\n", ans); } } }