← 返回 reddit 的题目列表Moderator Privilege Ranking System with Communities and Demotion
类型:online_judge
Problem: Moderator Privilege Ranking System with Communities and Demotion
Implement a system that tracks moderator privileges and moderator hierarchy for online communities.
You are given a chronological list of moderation logs. Each log indicates that a user either gains or loses moderator status in a community.
Within the same community, active moderators are ranked as follows:
A user who became an active moderator earlier has a higher rank.
A user who became an active moderator later has a lower rank.
If a user is removed and later added again, their rank is based on the most recent add time.
Implement ModSystem.
Log Format
After adding the community layer, each log string has the format:
<community>,<targetUser>,<action>,<actorUser>,<timestamp>
Where:
community: the community name.
targetUser: the user whose moderator status is affected.
action: either added or removed.
actorUser: the user who performed the action. During initialization, you do not need to validate this actor's permission.
timestamp: an integer represented as a string.
The logs are sorted by strictly increasing timestamp.
Required Operations
ModSystem(List<String> logs)
Initializes the system using the logs.
boolean canRemoveMod(String community, String targetUser, String actorUser)
Returns whether actorUser is allowed to remove targetUser as a moderator in the given community.
Return true only if all of the following are satisfied:
targetUser is currently a moderator in the community.
actorUser is currently a moderator in the community.
actorUser != targetUser.
actorUser has a higher moderator rank than targetUser.
Otherwise, return false.
List<String> getModRanking(String community)
Returns all current moderators in the given community, ordered from highest rank to lowest rank.
void demote(String community, String user)
Demotes user by exactly one position within the given community.
Rules:
If the current ranking is user1 -> user2 -> user3, calling demote(community, "user1") changes it to user2 -> user1 -> user3.
In other words, the user swaps with the moderator immediately below them.
If the user is already the lowest-ranked moderator, nothing changes.
If the user is not currently a moderator in that community, nothing changes.
If the community does not exist, nothing changes.
Input/Output Format for Testing
The first line contains integer N, the number of logs.
The next N lines each contain one log:
community,targetUser,action,actorUser,timestamp
Then one line contains integer Q, the number of operations.
The next Q lines each contain one operation:
CAN community targetUser actorUser
RANK community
DEMOTE community user
Output rules:
For CAN, print true or false.
For RANK, print the comma-separated moderator list. If empty, print EMPTY.
For DEMOTE, print nothing.
Constraints
0 <= N <= 2 * 10^5
0 <= Q <= 2 * 10^5
User names and community names have length at most 50.
Logs are sorted by timestamp in increasing order.
Timestamps can be parsed as integers.
Example
Input:
3
main,user1,added,system,1
main,user2,added,user1,2
main,user3,added,user1,3
5
RANK main
DEMOTE main user1
RANK main
CAN main user1 user2
CAN main user2 user1
Output:
user1,user2,user3
user2,user1,user3
true
false
Example
Input
4
main,alice,added,system,1
main,bob,added,alice,2
main,carol,added,bob,3
main,bob,removed,alice,4
3
RANK main
CAN main carol alice
CAN main alice carol
Output
alice,carol
true
false