Segmentation
InterviewTime limit1sMemory limit1024 MB
Track visits per user over time and answer queries by mapping each user's recency and frequency to one of 12 RF segments.
- Level
Medium4 of 10
- Topics
- Hash map, Implementation, Simulation, Array
- Solved
- No attempts yet
Problem
ZOYI builds a tool called Channel that lets a site talk with the online users who visit it. To sort the users of Channel, ZOYI recently adopted an RF (Recency / Frequency) model and decided to group users by the calculation below.

Here and , and every and is an integer.
Each online user gets an value and an value from the visit log, and falls into one of these 12 segments.
New CustomerPromisingAbout to SleepHibernatingLostPotential LoyalistNeed AttentionAbout to LeaveChampionLoyal CustomerCan't Lose ThemNone
None means the user has no visit on record. When the point lies on a boundary between two or more segments in the figure, use the segment of instead. For example, is Hibernating, and is Loyal Customer. With that rule applied, the segments are the following table.
You want to know who visits the RUN application site, so you install Channel there and analyze it. On this site the and of a visiting user are defined like this.
- : at the current time , the value of minus the time of that user's most recent visit
- : the number of visits by that user
Given the visit events on the site, write a program that classifies the customers by the rule above.
Input
The first line contains four natural numbers , , , in that order, separated by spaces.
The second line contains four natural numbers , , , in that order, separated by spaces.
The third line contains the number of events .
Each of the next lines describes one event in the order the events happened. The event on the -th of those lines happens at time .
An event is given as and separated by a space. is a user name, made of at most 10 uppercase and lowercase letters with no space. is either 1 or 2. A 1 means the user visited the site, and a 2 means you must print which segment that user is in at that moment.
Output
For every event whose is 2, print the segment of that customer, one per line. Do not print the quotation marks.
Constraints
Hint
Take the first example. At time 3, Alex has visited once and the most recent visit was at time 2, so and . That is New Customer.
At time 7, Alex has visited twice and the most recent visit was at time 6, so and . That is Potential Loyalist.
At time 8, RUN has visited three times and the most recent visit was at time 5, so and . That is Need Attention.