← 返回 pinterest 的题目列表Count Unique Pins by Policy and Date Range
类型:online_judge
Problem: Count Unique Pins by Policy and Date Range
You are given a list of violation records. Each record contains:
(pinId: int, policy: string, date: string)
It means that pinId violated policy on date. The same pinId may violate the same policy multiple times on the same or different dates, so all counts should deduplicate by pinId.
Process three types of queries:
Given a policy, return the number of unique pinIds that have violated that policy.
Given a date range [startDate, endDate], return the number of unique pinIds that violated any policy in that range.
Given a date range [startDate, endDate], return the number of unique pinIds per policy in that range.
Input Format
n
pinId_1 policy_1 date_1
pinId_2 policy_2 date_2
...
pinId_n policy_n date_n
q
query_1
query_2
...
query_q
Query formats:
1 policy
2 startDate endDate
3 startDate endDate
1 policy: type-1 query.
2 startDate endDate: type-2 query.
3 startDate endDate: type-3 query.
Output Format
Print one line for each query:
For type-1 and type-2 queries, print one integer.
For type-3 queries, print all policies that appear in the range and their unique pin counts in the following format:
policy1=count1 policy2=count2 ...
To make the output deterministic, print policies in lexicographical order. If there are no violation records in the range, print:
EMPTY
Constraints
1 <= n <= 5000
1 <= q <= 5000
1 <= pinId <= 10^9
1 <= len(policy) <= 50
date is in YYYY-MM-DD format
Date ranges are inclusive
startDate <= endDate
Example
Input:
5
1 spam 2024-01-01
1 spam 2024-01-02
2 spam 2024-01-03
2 copyright 2024-01-03
3 nudity 2024-02-01
3
1 spam
2 2024-01-01 2024-01-31
3 2024-01-01 2024-12-31
Output:
2
2
copyright=1 nudity=1 spam=2
Example
Input
5
1 spam 2024-01-01
1 spam 2024-01-02
2 spam 2024-01-03
2 copyright 2024-01-03
3 nudity 2024-02-01
3
1 spam
2 2024-01-01 2024-01-31
3 2024-01-01 2024-12-31
Output
2
2
copyright=1 nudity=1 spam=2