CCL's Sequence

TimeLimit:5000MS  MemoryLimit:100MB
64-bit integer IO format:%lld
未提交 | 登录后收藏
Problem Description

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.


Input

Single test case.

The first line has two numbers, indicating n, m. (1n, m100000).

The second line, n numbers, indicates  s1,s2,...,sn . ( the absolute value of  s 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.


Output

For each operation, output the result of the codes given above.


SampleInput
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
SampleOutput
2147483647
1
1
1
1
1
1
1
1
1
Submit
题目统计信息详细
总AC数11
通过人数7
尝试人数10
总提交量30
AC率23.33%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签
作者

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: