#include using namespace std; #include #include #include #include #include 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; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; using P=pair; const int INF=INT_MAX; const int mod=1e9+7; struct SegmentTree { private: int n; vector> node; public: vectorcomp(vectorl,vectorr){ int sz=l.size(); vectors(sz); rep(i,sz){s[i]=r[l[i]];} return s; } SegmentTree(int m,int sz) { n = 1; while(n < m) n *= 2; vectorres(sz); iota(res.begin(),res.end(),0); node.resize(2*n-1,res); for(int i=0; i=0; i--) node[i] = comp(node[2*i+1],node[2*i+2]); } void update(int x, vector val) { x += (n - 1); node[x] = val; while(x > 0) { x = (x - 1) / 2; int sz=val.size(); node[x] = comp(node[2*x+1],node[2*x+2]); } } vector get(int a, int b, int sz,int k=0, int l=0, int r=-1) { vectorres(sz); iota(res.begin(),res.end(),0); if(r < 0) r = n; if(r <= a || b <= l) return res; if(a <= l && r <= b) return node[k]; auto vl = get(a, b,sz, 2*k+1, l, (l+r)/2); auto vr= get(a, b,sz, 2*k+2, (l+r)/2, r); res=comp(vl,vr); return res; } }; void solve(){ int n,m,q; cin>>n>>m>>q; SegmentTree seg(m,n); rep(Q,q){ int t; cin>>t; if(t==1){ int d; cin>>d;d--; vectorp(n); rep(j,n){cin>>p[j];p[j]--;} seg.update(d,p); } if(t==2){ int s; cin>>s; vectorp=seg.get(0,s,n); vectorres(n); rep(j,n){res[p[j]]=j;} rep(j,n){printf("%d%c",res[j]+1,(j==n-1?'\n':' '));} } if(t==3){ int l,r; cin>>l>>r; vector p=seg.get(l-1,r,n); int ans=0; rep(j,n){ ans+=abs(p[j]-j); } cout<