← 返回 airbnb 的题目列表Working Hours Register with Promotions and Double-Pay Periods
类型:online_judge
Problem: Working Hours Register
Implement a WorkingHoursRegister that tracks office check-ins/check-outs, total worked time, delayed promotions, salary calculation, and double-pay grant periods.
Each employee is identified by a unique string employee_id. Timestamps are non-negative comparable integers. A completed work session consists of an ENTER followed by an EXIT; its duration is exit_time - enter_time.
Input
The first line contains an integer Q, followed by Q operations:
ADD <employee_id> <position> <rate>: Add an employee with an initial position and hourly rate.
ENTER <employee_id> <timestamp>: Check in. If a promotion is pending, apply it now. The session uses the rate active at check-in.
EXIT <employee_id> <timestamp>: Check out and complete the current session.
TOP <position> <n>: Print up to n employees whose current position is position, sorted by completed work time descending and then employee ID ascending. Format each result as employee_id(hours), separated by spaces.
PROMOTE <employee_id> <new_position> <new_rate>: Store a pending promotion. It does not affect the employee until their next ENTER.
GRANT <employee_id> <start> <end>: Add a double-pay interval [start, end]. A session is double-paid if its full interval is contained in at least one grant interval.
SALARY <employee_id> <start> <end>: Print total pay for completed sessions fully contained in [start, end]. A session contributes duration × rate_at_enter, doubled when it is fully contained in any grant interval.
Constraints
1 <= Q <= 2 * 10^5
IDs and positions contain no spaces.
Rates and timestamps are non-negative integers; rate <= 10^9.
Operations for each employee are valid. Incomplete sessions do not contribute to work time or salary.
Example
12
ADD alice engineer 10
ADD bob engineer 20
ENTER alice 1
EXIT alice 5
TOP engineer 2
PROMOTE alice senior_engineer 30
ENTER alice 10
EXIT alice 12
GRANT alice 9 15
SALARY alice 0 20
TOP engineer 2
TOP senior_engineer 2
Output:
alice(4) bob(0)
160
bob(0)
alice(6)
Example
Input
7
ADD e1 dev 10
ENTER e1 3
EXIT e1 8
TOP dev 1
SALARY e1 0 10
TOP manager 3
SALARY e1 4 10
Output
e1(5)
50
0