- Decide the key that represents the information needed later.
- Update its count or stored state while scanning the input.
- Use constant-time expected lookups to detect matches or assemble the result.
Code notes
- 47 lines of Python from the credited upstream file abc304_d.py.
- The implementation visibly relies on sequence storage, hash lookup, ordered lookup.
- No explicit loop blocks detected.
Complexity
Expected hash operations are constant time, but the surrounding scan and the number of stored keys determine total work and memory.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4from bisect import bisect_left, bisect_right5from typing import List6 7 8def bisect_lt(sorted_array: List[int], value: int):9 """Find the largest element < x and its index, or None if it doesn't exist."""10 11 if sorted_array[0] < value:12 index: int = bisect_left(sorted_array, value) - 113 14 return index, sorted_array[index]15 16 return None, None17 18 19def main():20 import sys21 from collections import defaultdict22 23 input = sys.stdin.readline24 25 w, h = map(int, input().split())26 n = int(input())27 pq = [tuple(map(int, input().split())) for _ in range(n)]28 a_count = int(input())29 a = [0] + list(map(int, input().split())) + [w]30 b_count = int(input())31 b = [0] + list(map(int, input().split())) + [h]32 ans = defaultdict(int)33 34 for pi, qi in pq:35 i, value1 = bisect_lt(a, pi)36 j, value2 = bisect_lt(b, qi)37 ans[(i, j)] += 138 39 if (a_count + 1) * (b_count + 1) - len(ans.keys()) > 0:40 print(0, max(ans.values()))41 else:42 print(min(ans.values()), max(ans.values()))43 44 45if __name__ == "__main__":46 main()47