#include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template struct segtree{ int n; T UNIT; vector dat; T (*calc)(T, T); segtree(int n_, T unit, T (*_calc)(T, T)){ UNIT = unit; calc = _calc; n = 1; while(n < n_) n *= 2; dat = vector(2*n); for(int i = 0; i < 2*n; i++) dat[i] = UNIT; } void insert(int k, T a){ dat[k+n-1] = a; } void update_all(){ for(int i = n-2; i >= 0; i--){ dat[i] = calc(dat[i*2+1], dat[i*2+2]); } } //k番目の値(0-indexed)をaに変更 void update(int k, T a){ k += n-1; dat[k] = a; while(k > 0){ k = (k-1)/2; dat[k] = calc(dat[k*2+1], dat[k*2+2]); } } //[a, b) //区間[a, b]へのクエリに対してはquery(a, b+1)と呼ぶ T query(int a, int b, int k=0, int l=0, int r=-1){ if(r < 0) r = n; if(r <= a || b <= l) return UNIT; if(a <= l && r <= b) return dat[k]; else{ T vl = query(a, b, k*2+1, l, (l+r)/2); T vr = query(a, b, k*2+2, (l+r)/2, r); return calc(vl, vr); } } }; int f(vector v){ int ans = 0; for(int i = 0; i < v.size(); i++) ans += abs(v[i]-i); return ans; } vector calc(vector p1, vector p2){ int n = p1.size(); vector v1(n), v2(n); for(int i = 0; i < n; i++){ v1[p1[i]] = i; } for(int i = 0; i < n; i++){ v2[p2[i]] = v1[i]; } vector ans(n); for(int i = 0; i < n; i++) ans[v2[i]] = i; return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m, q; cin >> n >> m >> q; vector unit(n); for(int i = 0; i < n; i++) unit[i] = i; segtree> sgt_ope(m, unit, calc); while(q--){ int t; cin >> t; if(t == 1){ int d; cin >> d; d--; vector p(n); for(int i = 0; i < n; i++){ cin >> p[i]; p[i]--; } sgt_ope.update(d, p); }else if(t == 2){ int s; cin >> s; s--; auto p = sgt_ope.query(0, s+1); vector ans(n); for(int i = 0; i < n; i++) ans[p[i]] = i; for(int x: ans) cout << x+1 << ' '; cout << endl; }else{ int l, r; cin >> l >> r; l--; r--; auto p = sgt_ope.query(l, r+1); cout << f(p) << endl; } } }