Problem H

Statement
Copy Copied
H. Ice Baby
time limit per test2 seconds
memory limit per test512 megabytes
The longest non-decreasing subsequence of an array of integers π‘Ž1,π‘Ž2,…,π‘Žπ‘› is the longest sequence of indices 1≀𝑖1<𝑖2<…<π‘–π‘˜β‰€π‘› such that π‘Žπ‘–1β‰€π‘Žπ‘–2β‰€β€¦β‰€π‘Žπ‘–π‘˜. The length of the sequence is defined as the number of elements in the sequence. For example, the length of the longest non-decreasing subsequence of the array π‘Ž=[3,1,4,1,2] is 3.

You are given two arrays of integers 𝑙1,𝑙2,…,𝑙𝑛 and π‘Ÿ1,π‘Ÿ2,…,π‘Ÿπ‘›. For each 1β‰€π‘˜β‰€π‘›, solve the following problem:

Consider all arrays of integers π‘Ž of length π‘˜, such that for each 1β‰€π‘–β‰€π‘˜, it holds that π‘™π‘–β‰€π‘Žπ‘–β‰€π‘Ÿπ‘–. Find the maximum length of the longest non-decreasing subsequence among all such arrays.
Input
Each test consists of multiple test cases. The first line contains a single integer 𝑑 (1≀𝑑≀10^4) β€” the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer 𝑛 (1≀𝑛≀2β‹…10^5) β€” the length of the arrays 𝑙 and π‘Ÿ.

The next 𝑛 lines of each test case contain two integers 𝑙𝑖 and π‘Ÿπ‘– (1β‰€π‘™π‘–β‰€π‘Ÿπ‘–β‰€10^9).

It is guaranteed that the sum of 𝑛 across all test cases does not exceed 2β‹…10^5.

Output
For each test case, output 𝑛 integers: for each π‘˜ from 1 to 𝑛, output the maximum length of the longest non-decreasing subsequence among all suitable arrays.