Quietly, Completely, Forever
Time limit1sMemory limit1024 MB
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 of length . Then updates are given as follows.
L R x: For every , apply . (; )Find the sequence after performing the 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 -th update, then that element is an -forgotten element. Note that for any two positive integers , every -forgotten element is also a -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 , the length of the sequence. ()
The second line contains integers , separated by spaces. ()
The third line contains an integer , the number of updates. ()
From the fourth line, 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 integers , separated by spaces. Here, is the number of -forgotten elements.