Under construction

Still being built. Things may change

Quietly, Completely, Forever

Time limit1sMemory limit1024 MB

Summary
Apply range chmin updates to an array in order, output the final array, and count elements that no later update changes after each step.
Level

Medium7 of 10

Topics
Segment tree, Implementation
Solved
No attempts yet

Problem

Sejong is solving the following problem.

You are given a sequence A1,A2,⋯ ,ANA_1,A_2,\cdots,A_N of length NN. Then QQ updates are given as follows.

  • L R x: For every L≤i≤RL\leq i\leq R, apply Ai=min⁡(Ai,x)A_i=\min(A_i,x). (1≤L≤R≤N1\leq L\leq R\leq N; 0≤x≤1 000 0000\leq x\leq 1\,000\,000)

Find the sequence after performing the QQ updates in order.

Sejong found that some elements stop changing after a certain update. The emotional Sejong calls these elements forgotten elements and decides to keep count of them. Specifically, if an element is not changed by the remaining updates after it processes the ii-th update, then that element is an ii-forgotten element. Note that for any two positive integers i<ji<j, every ii-forgotten element is also a jj-forgotten element.

Write a program that finds the sequence Sejong needs and the number of forgotten elements after each update.

Input

The first line contains an integer NN, the length of the sequence. (1≤N≤100 0001\leq N\leq 100\,000)

The second line contains NN integers A1,A2,⋯ ,ANA_1,A_2,\cdots,A_N, separated by spaces. (0≤Ai≤1 000 0000\leq A_i\leq 1\,000\,000)

The third line contains an integer QQ, the number of updates. (1≤Q≤100 0001\leq Q\leq 100\,000)

From the fourth line, QQ lines follow, one update per line, in the order they must be processed.

Output

On the first line, print the sequence after all updates are performed, separated by spaces.

On the second line, print QQ integers D1,D2,⋯ ,DQD_1,D_2,\cdots,D_Q, separated by spaces. Here, DiD_i is the number of ii-forgotten elements.

Examples1

  1. Example 1

    Input
    10
    10 5 6 9 2 4 7 1 8 3
    5
    1 2 8
    2 4 6
    5 9 4
    8 10 1
    3 6 7
    
    Expected output
    8 5 6 6 2 4 4 1 1 1
    6 7 8 10 10