Let $n$ be a positive integer. $S_1, S_2, \ldots, S_n$ are pairwise non-intersecting sets, and $S_k $ has exactly $k$ elements $(k = 1, 2, \ldots, n)$. Define $S = S_1\cup S_2\cup\cdots \cup S_n$. The function $f: S \to S $ maps all elements in $S_k$ to a fixed element of $S_k$, $k = 1, 2, \ldots, n$. Find the number of functions $g: S \to S$ satisfying $f(g(f(x))) = f(x).$
1. **Define the sets and function:**
   Let \( S_1, S_2, \ldots, S_n \) be pairwise non-intersecting sets where \( S_k \) has exactly \( k \) elements for \( k = 1, 2, \ldots, n \). Define \( S = S_1 \cup S_2 \cup \cdots \cup S_n \). The function \( f: S \to S \) maps all elements in \( S_k \) to a fixed element \( x_k \in S_k \).

2. **Identify the fixed elements:**
   Let \( x_k \) be the fixed element in \( S_k \) such that \( f(s_k) = x_k \) for all \( s_k \in S_k \). Let \( X = \{x_1, x_2, \ldots, x_n\} \). Therefore, \( f(x) \in X \) for all \( x \in S \).

3. **Analyze the condition \( f(g(f(x))) = f(x) \):**
   For \( f(g(f(x))) = f(x) \) to hold, we need \( g(x_k) \in S_k \) for each \( k \). This is because \( f(g(x_k)) = x_k \) implies \( g(x_k) \) must be an element of \( S_k \).

4. **Count the possible values of \( g(x_k) \):**
   Since \( g(x_k) \in S_k \) and \( S_k \) has \( k \) elements, \( g(x_k) \) can take \( k \) different values. Therefore, the number of possible functions \( g \) restricted to \( X \) is:
   \[
   \prod_{i=1}^n i = n!
   \]

5. **Consider elements \( s \in S \setminus X \):**
   For elements \( s \in S \setminus X \), there are no restrictions on \( g(s) \). The cardinality of \( S \setminus X \) is:
   \[
   \sum_{i=1}^n i - n = \frac{n(n+1)}{2} - n = \frac{n(n-1)}{2}
   \]
   The cardinality of \( S \) is:
   \[
   \sum_{i=1}^n i = \frac{n(n+1)}{2}
   \]

6. **Count the possible values of \( g(s) \) for \( s \in S \setminus X \):**
   Each of the \( \frac{n(n-1)}{2} \) elements in \( S \setminus X \) can be mapped to any of the \( \frac{n(n+1)}{2} \) elements in \( S \). Therefore, the number of possible mappings is:
   \[
   \left( \frac{n(n-1)}{2} \right) \cdot \left( \frac{n(n+1)}{2} \right) = \frac{n^2(n-1)(n+1)}{4}
   \]

7. **Combine the results:**
   The total number of functions \( g: S \to S \) satisfying \( f(g(f(x))) = f(x) \) is:
   \[
   n! \cdot \frac{n^2(n-1)(n+1)}{4} = \frac{(n+1)!n^2(n-1)}{4}
   \]

The final answer is \(\boxed{\frac{(n+1)!n^2(n-1)}{4}}\).