Codeforces Round 111 (Div. 2)
E
Buses and People
Codeforces
2400
原题
← D→
翻译中…

The main Bertown street is represented by a straight line. There are $10^{9}$ bus stops located on the line. The stops are numbered with integers from $1$ to $10^{9}$ in the order in which they follow on the road. The city has $*n*$ buses. Every day the $*i*$-th bus drives from stop number $*s*_{*i*}$ to stop number $*f*_{*i*}$ ($*s*_{*i*} < *f*_{*i*}$), it stops on all intermediate stops and returns only at night. The bus starts driving at time $*t*_{*i*}$ and drives so fast that it finishes driving also at time $*t*_{*i*}$. The time $*t*_{*i*}$ is different for all buses. The buses have infinite capacity.

翻译中…

Bertown has $*m*$ citizens. Today the $*i*$-th person should get from stop number $*l*_{*i*}$ to stop number $*r*_{*i*}$ ($*l*_{*i*} < *r*_{*i*}$); the $*i*$-th citizen comes to his initial stop ($*l*_{*i*}$) at time $*b*_{*i*}$. Each person, on the one hand, wants to get to the destination point as quickly as possible, and on the other hand, definitely does not want to change the buses as he rides. More formally: the $*i*$-th person chooses bus $*j*$, with minimum time $*t*_{*j*}$, such that $*s*_{*j*} ≤ *l*_{*i*}$, $*r*_{*i*} ≤ *f*_{*j*}$ and $*b*_{*i*} ≤ *t*_{*j*}$.

翻译中…

Your task is to determine for each citizen whether he can ride to the destination point today and if he can, find the number of the bus on which the citizen will ride.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 10^{5}$) — the number of buses and the number of people.

翻译中…

Then $*n*$ lines follow, each of them contains three integers: $*s*_{*i*}$, $*f*_{*i*}$, $*t*_{*i*}$ ($1 ≤ *s*_{*i*}, *f*_{*i*}, *t*_{*i*} ≤ 10^{9}, *s*_{*i*} < *f*_{*i*}$) — the description of the buses. It is guaranteed that all $*t*_{*i*}$-s are different.

翻译中…

Then $*m*$ lines follow, each of them contains three integers: $*l*_{*i*}$, $*r*_{*i*}$, $*b*_{*i*}$ ($1 ≤ *l*_{*i*}, *r*_{*i*}, *b*_{*i*} ≤ 10^{9}, *l*_{*i*} < *r*_{*i*}$) — the Bertown citizens' description. Some $*b*_{*i*}$-s could coincide.

翻译中…

Output

翻译中…

In the first line print $*m*$ space-separated integers: the $*i*$-th number should be equal either to -1, if the person number $*i*$ can't get to the destination point, or to the number of the bus that will ride the person number $*i*$. The buses are numbered with integers from $1$ to $*n*$ in the input order.

翻译中…

样例

Input #1
4 3
1 10 10
5 6 2
6 7 3
5 7 4
5 7 1
1 2 1
1 10 11
Output #1
4 1 -1
InputCopy OutputCopy
Input #2
1 1
1 1000000000 1000000000
1 1000000000 1000000000
Output #2
1
InputCopy OutputCopy
题目信息
题号
160E
时间限制
1 s
内存限制
256 MB
标签
二分
数据结构
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。