Given a sequence s of length n, and there are m operations.
The content of each operation is: given y, z, all y in the sequence will become z.
At the same time we have the following codes:
int ans = 2147483647; for (int j = 1; j <= n; j++) { for (int k = j + 1; k <= n; k++) { if (s[j] == s[k]) ans = std::min(ans, k - j); } } std::cout << ans << std::endl;
Please output the result of the codes after each operation.
Single test case.
The first line has two numbers, indicating n, m. (1≤n, m≤100000).
The second line, n numbers, indicates s1,s2,...,sn . ( the absolute value of si is in the range of int)
Then there are m lines, each line has two numbers y and z per line, indicating that all y in the sequence will become z.
For each operation, output the result of the codes given above.
5 10 2 7 6 3 8 6 1 7 1 1 3 5 6 1 7 9 5 1 10 7 6 7 5 3 9
2147483647 1 1 1 1 1 1 1 1 1