#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; #define REP(i,n) for(ll i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template bool chmax(T &x, const T &y) {return (x bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;}; constexpr ll MOD=998244353; constexpr ll INF=2e18; template struct Segtree{ using F=function; int n; F f; X ex; vector dat; Segtree(int n_, F f, X ex) :f(f), ex(ex){ n=1; while(n_>n){n*=2;} dat.assign(2*n,ex); } void set(int i, X x){ dat[i+n-1]=x; } void build(){ for(int k=n-2;k>=0;k--) dat[k]=f(dat[2*k+1],dat[2*k+2]); } void update(int i, X x){ i+=n-1; dat[i]=x; while(i>0){ i=(i-1)/2; dat[i]=f(dat[i*2+1],dat[i*2+2]); } } X query(int a, int b){ return query_sub(a,b,0,0,n); } X query_sub(int a, int b, int k, int l, int r){ if(r<=a||b<=l) return ex; else if(a<=l&&r<=b) return dat[k]; else{ X vl=query_sub(a,b,k*2+1,l,(l+r)/2); X vr=query_sub(a,b,k*2+2,(l+r)/2,r); return f(vl,vr); } } }; VI f(VI a, VI b){ int n=a.size(); VI ret(n); REP(i,n){ ret[i]=b[a[i]]; } return ret; } int main(){ int n, m, q; cin >> n >> m >> q; VI e(n); iota(ALL(e),0); Segtree seg(m+1,f,e); int t, d, x, s, l, r, sum; VI p(n); REP(i,q){ cin >> t; if(t==1){ cin >> d; REP(j,n) cin >> p[j], p[j]--; seg.update(d,p); } else if(t==2){ cin >> s; VI ans=seg.query(0,s+1); VI ans2(n); REP(j,n) ans2[ans[j]]=j; REP(j,n) cout << ans2[j]+1 << " "; cout << endl; } else{ cin >> l >> r; VI ans=seg.query(l,r+1); sum=0; REP(j,n) sum+=abs(j-ans[j]); cout << sum << endl; } } return 0; }