Killer Monsters
Practice
3.7 (10 votes)
Stacks
Basics of stacks
Sets
Data structures
Problem
69% Success 3609 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code
Given an array \(monsters\) denoting strengths of \(N\) monsters, we start with an empty battlefield, at each minute \(i\), the \(i^{th}\) monster joins the battlefield and kills all monsters whose strength is less than or equal to his strength.
Find the number of monsters alive in the battlefield at end of \(i^{th}\) minute for each \(0 \le i < N\).
NOTE:
- Use of Fast I/O is recommended for this problem.
- \(i^{th}\) monster becomes part of the battlefield at the end of killing spree.
Input Format:
- First line contains an integer \(T\), the number of test cases.
- First line of each testcase contains an integer \(N\), the number of monsters..
- Second line of each testcase contains \(N\) space seperated integers, the strengths of \(N\).monsters.
Output Format:
- For each testcase, output \(N\) integers denoting the number of monsters alive after \(i^{th}\) minute for each \(0 \le i < N\).
Constraints:
- \(1 \le T \le10\)
- \(1 \le N \le 5 \times 10^5\)
- \(0 \le monsters[i] \le 10^4\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
53 votes
Tags:
Data StructuresDynamic programmingEasyStacks
Points:20
78 votes
Tags:
ArraysBasic ProgrammingData StructuresEasyImplementationStackseasy
Points:20
48 votes
Tags:
Data StructuresEasyHiringQueueStacks
Editorial