Language: C++

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

unsigned int y=11451419;

int rand_int(int l=0,int r=11451419){
	y=y^(y<<13);
	y=y^(y>>17);
	y=y^(y<<5);
	return y%(r-l+1)+l;
}

template<class T>
struct treap{
	struct node_t{
		T val; // 値
		node_t *lch, *rch;
		int pri; // 優先度
		int cnt; // 部分木のサイズ
		T sum; // 部分木の値の和
		node_t(T v, int p):val(v), pri(p), cnt(1), sum(v){
			lch = rch = NULL;
		}
	};
	node_t *root;
	treap():root(NULL){}
	int count(node_t *t){ return t ? t->cnt : 0; }
	T sum(node_t *t){ return t ? t->sum : 0; }
	node_t *update(node_t *t){
    	t->cnt = count(t->lch) + count(t->rch) + 1;
    	t->sum = sum(t->lch) + sum(t->rch) + t->val;
    	return t;
    }

    //木rを木lの後に追加する
    node_t *merge(node_t *l, node_t *r){
    	if(!l || !r) return l?l:r;
        if(l->pri > r->pri){ // 左の部分木の根のほうが優先度が高い
        	l->rch = merge(l->rch, r);
        	return update(l);
        }else{
        	r->lch = merge(l, r->lch);
        	return update(r);
        }
    }

    pair<node_t*, node_t*> split(node_t *t, int k){ // [0,k), [k,n)
    	if(!t) return {NULL,NULL};
    	if(k <= count(t->lch)){
    		pair<node_t*,node_t*> s = split(t->lch,k);
    		t->lch = s.second;
    		return {s.first, update(t)};
    	}else{
    		pair<node_t*,node_t*> s = split(t->rch, k-count(t->lch)-1);
    		t->rch = s.first;
    		return {update(t), s.second};
    	}
    }

    node_t *insert(node_t *t, int k, T val, int pri){
    	pair<node_t*,node_t*> s = split(t,k);
    	t = merge(s.first, new node_t(val,pri));
    	t = merge(t, s.second);
    	return update(t);
    }

    node_t *erase(node_t *t, int k){
    	pair<node_t*,node_t*> s2 = split(t,k+1);
    	pair<node_t*,node_t*> s1 = split(s2.first, k);
    	t = merge(s1.first, s2.second);
    	return update(t);
    }

    node_t *find(node_t *t, int k){
    	int c = count(t->lch);
    	if(k < c) return find(t->lch,k);
    	if(k == c) return t;
    	return find(t->rch, k-c-1);
    }

    void insert(int k, T val){ root = insert(root, k, val, rand_int()); }
    void erase(int k){ root = erase(root, k); }
    node_t *find(int k){ return find(root,k); }

};

treap<char> tr[1000005];
int n,q;

int main(void){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		for(int j=0;j<str.size();j++){
			tr[i].insert(j,str[j]);
		}
	}
	for(int i=0;i<q;i++){
		int type;
		scanf("%d",&type);
		if(type==1){
			int a,b,c,d;
			scanf("%d%d%d%d",&a,&b,&c,&d);
			a--;
			b--;
			c--;
			d--;
			auto sa=tr[a].split(tr[a].root,b);
			auto sc=tr[c].split(tr[c].root,d);
			tr[a].root=tr[a].merge(sa.first,sc.second);
			tr[c].root=tr[c].merge(sc.first,sa.second);
		}else{
			int a,b;
			char c;
			scanf("%d%d%*c%c%*c",&a,&b,&c);
			a--;
			b--;
			if(tr[a].count(tr[a].count)<b)while(1);
			tr[a].erase(b);
			tr[a].insert(b,c);
		}
	}
	for(int i=0;i<n;i++){
		int v=tr[i].count(tr[i].root);
		for(int j=0;j<v;j++){
			printf("%c",tr[i].find(j)->val);
		}
		printf("\n");
	}
	return 0;
} 


Compiler output:
a.cc: In function 'int main()':
a.cc:122:46: error: invalid use of non-static member function 'int treap<T>::count(node_t*) [with T = char]'
  122 |                         if(tr[a].count(tr[a].count)<b)while(1);
      |                                        ~~~~~~^~~~~
a.cc:30:13: note: declared here
   30 |         int count(node_t *t){ return t ? t->cnt : 0; }
      |             ^~~~~