problems / 217

Suki's Activity Intervals

easy intervals binary-search sorting 1000 ms · 256 MB

Suki's Activity Intervals

Suki keeps a detailed log of her daily activities, each marked with a start time and an end time. Her activities include napping in sunny spots, digging in the garden, fetching pink balls, and waiting by the door for her walk.

Given her activity log and several query times, determine which activity Suki was doing at each query time. If no activity was happening at a query time, she was idle.

Input

The first line contains n and q (1 ≤ n ≤ 2·10^5, 1 ≤ q ≤ 2·10^5), the number of activities and queries.

The next n lines each contain three integers: id, start, and end (1 ≤ id ≤ n, 0 ≤ start < end ≤ 10^9), where id is the activity identifier, start is the start time (inclusive), and end is the end time (exclusive).

The last q lines each contain one integer t (0 ≤ t < 10^9), a query time.

Activities are given in no particular order. Activity IDs are distinct. An activity is ongoing at time t if start ≤ t < end.

Output

For each query time, print the ID of the activity happening at that time, or print IDLE if no activity was happening.

Notes

Suki's activities do not overlap. Each query time is handled independently.

Example 1

Input

4 5
1 10 20
2 30 40
3 50 60
4 70 80
15
35
5
45
75

Output

1
2
IDLE
IDLE
4

Example 2

Input

3 4
5 0 100
10 100 200
7 200 300
50
150
250
1000000000

Output

5
10
7
IDLE

Hints · reveal one at a time if you're stuck

Hint 1

The activities don't overlap. So for a given query time, how many activities can possibly contain it?

Hint 2

Sort the activities by start time. The only activity that can contain t is the last one that starts at or before t, and you can find it with a binary search for each query.

Hint 3

Check that this candidate really covers t. The interval is half-open: it contains its start time, but not its end time.

report an issue Prefer your own editor? sooks prep 217 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.