func_code_string: #include <bits/stdc++.h>   using namespace std;   struct ty {     int d[4][11], a;   } t[400005], ans;   int n, m, q, x, y, a[11][100005], co[42], col, fa1, fa2, fa[42];   int find(int x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   ty update(ty x, ty y) {     ty z;     for (int i = 1; i <= n; i++) {       fa[x.d[3][i]] = x.d[3][i];       fa[x.d[2][i]] = x.d[2][i];       fa[y.d[2][i] + 20] = y.d[2][i] + 20;       fa[y.d[3][i] + 20] = y.d[3][i] + 20;     }     z.a = x.a + y.a;     int col = 0;     memset(co, 0, sizeof(co));     for (int i = 1; i <= n; i++)       if (x.d[1][i] == y.d[0][i]) {         fa1 = find(x.d[3][i]);         fa2 = find(y.d[2][i] + 20);         if (fa1 != fa2) {           z.a--;           fa[fa2] = fa1;         }       }     for (int i = 1; i <= n; i++) {       z.d[0][i] = x.d[0][i];       z.d[1][i] = y.d[1][i];       fa1 = find(x.d[2][i]);       if (!co[fa1]) co[fa1] = ++col;       z.d[2][i] = co[fa1];       fa1 = find(y.d[3][i] + 20);       if (!co[fa1]) co[fa1] = ++col;       z.d[3][i] = co[fa1];     }     return z;   }   void build(int o, int l, int r) {     if (l == r) {       t[o].a = 0;       int col = 0;       for (int i = 1; i <= n; i++) {         t[o].d[0][i] = t[o].d[1][i] = a[i][l];         if (a[i][l] != a[i - 1][l]) {           t[o].a++;           col++;         }         t[o].d[2][i] = t[o].d[3][i] = col;       }       return;     }     int mid = (l + r) >> 1;     build(o * 2, l, mid);     build(o * 2 + 1, mid + 1, r);     t[o] = update(t[o * 2], t[o * 2 + 1]);   }   ty find(int o, int l, int r, int L, int R) {     if (l == L && r == R) return t[o];     int mid = (l + r) >> 1;     if (R <= mid)       return find(o * 2, l, mid, L, R);     else if (L > mid)       return find(o * 2 + 1, mid + 1, r, L, R);     else       return update(find(o * 2, l, mid, L, mid),                     find(o * 2 + 1, mid + 1, r, mid + 1, R));   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int r = 1; r <= m; r++) scanf( %d , &a[i][r]);     build(1, 1, m);     for (int i = 1; i <= q; i++) {       scanf( %d%d , &x, &y);       ans = find(1, 1, m, x, y);       printf( %d n , ans.a);     }   }   