#P12262. 『STA - R9』交错

『STA - R9』交错

Problem Description

A sequence pp of length mm is called an interleaving sequence if and only if it has the form x,y,x,y,{x,y,x,y,\cdots} and xyx\ne y.

You are given a sequence a1na_{1\dots n} of length nn and qq modifications. In each modification, two positive integers kk and cc are given, and ak=ca_{k}=c is set. You need to find the length of the longest interleaving subsequence of aa initially (i.e., before the first modification) and after each modification.

Input Format

The first line contains a positive integer nn.

The second line contains nn positive integers, denoting aa.

The third line contains a non-negative integer qq.

The next qq lines each contain two positive integers k,ck,c, denoting one modification.

Output Format

Output q+1q+1 lines.

The first line is the length of the longest interleaving subsequence of aa initially.

The next qq lines: the ii-th line is the length of the longest interleaving subsequence of aa after the ii-th modification.

5
2 3 1 3 3 
1
2 3
3
3

Hint

This problem uses bundled testdata, and the subtasks are as follows:

Subtask ID nn\le qq\le Special Property Score
0 11 00 None 22
1 2020 55
2 30003000 70007000 ai,c2a_{i},c\le 2 2323
3 250250 00 None 1010
4 10001000
5 20002000
6 30003000 1515
7 70007000 2525

For 100%100\% of the data, it is guaranteed that 1n30001\le n\le 3000, 0q70000\le q\le 7000, and 1ai,k,cn1\le a_{i},k,c\le n.

Translated by ChatGPT 5