#include #include using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; int n; struct S { int d[18]; }; S op(S f, S g) { S h; // h = f;g rep(i, n) h.d[i] = g.d[f.d[i]]; return h; } S e() { S f; rep(i, 18) f.d[i] = i; return f; } int main() { ios::sync_with_stdio(false); cin.tie(0); int m, q; cin >> n >> m >> q; segtree seg(q); rep(_, q) { int type; cin >> type; if (type == 1) { int d; cin >> d, d--; S p; rep(i, n) cin >> p.d[i], p.d[i]--; seg.set(d, p); } else if (type == 2) { int s; cin >> s; auto p = seg.prod(0, s); int rank[18]; rep(i, n) rank[p.d[i]] = i; rep(i, n) cout << rank[i] + 1 << " \n"[i + 1 == n]; } else { int l, r; cin >> l >> r, l--; auto p = seg.prod(l, r); int ans = 0; rep(i, n) ans += abs(i - p.d[i]); cout << ans << '\n'; } } }