← 返回 pinterest 的题目列表Grant Access (permissions propagation / access control)
类型:online_judge
Implement the core logic of a “Grant Access” permission system on a hierarchical resource tree (e.g., Org -> Project -> Folder -> Document).
You can grant or revoke a permission (e.g., READ) for a user at any node. The rule applies to the node and all its descendants, unless a more specific rule is applied deeper in the tree. Later operations override earlier ones.
Design a data structure supporting:
grant(user, node)
revoke(user, node)
check(user, node) -> bool
Constraints:
Up to N = 2*10^5 nodes and Q = 2*10^5 operations.
Must handle multiple grants/revokes with overriding semantics.
Define a clear input format and output true/false for each check.