← 返回 waymo 的题目列表Autocomplete Search Bar with Debounce
类型:online_judge
Problem: Implement an Autocomplete Search Bar with Debounce
Implement the core logic of an autocomplete search bar.
When the user types continuously, the system should not request the search API on every keystroke. Instead, it should debounce requests: only after the user stops typing for delay milliseconds should a search request be triggered.
For online judging, this problem simulates user input with an event sequence.
Input Format
The first line contains an integer delay, the debounce time in milliseconds.
The second line contains an integer n, the number of input events.
The next n lines each contain:
time query
time: timestamp of the input event in milliseconds, strictly increasing.
query: the full current value in the input box.
Output Format
Print the actual search request trigger time and query.
Each line should be:
trigger_time query
After an input event, if no new input arrives within delay milliseconds, trigger a search at time + delay.
If a new input event happens exactly at the previously scheduled trigger time, the new input happens first and the old scheduled search is cancelled.
Constraints
1 <= delay <= 10^5
1 <= n <= 10^5
0 <= time <= 10^9
query.length <= 100
query contains no spaces
Example
Input:
300
4
0 a
100 ab
250 abc
700 abcd
Output:
550 abc
1000 abcd
Example
Input
300
4
0 a
100 ab
250 abc
700 abcd
Output
550 abc
1000 abcd