跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2933. Buses and People

    ID: 2939 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>二分数据结构排序算法思想编程与模拟挑战难度共享题库Codeforces英文题面题目来源题面语言

Buses and People

题目描述

E. Buses and People
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The main Bertown street is represented by a straight line. There are 109 bus stops located on the line. The stops are numbered with integers from 1 to 109 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 si to stop number fi (si<fi), it stops on all intermediate stops and returns only at night. The bus starts driving at time ti and drives so fast that it finishes driving also at time ti. The time ti is different for all buses. The buses have infinite capacity.

Bertown has m citizens. Today the i-th person should get from stop number li to stop number ri (li<ri); the i-th citizen comes to his initial stop (li) at time bi. 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 tj, such that sjli, rifj and bitj.

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≤105) − the number of buses and the number of people.

Then n lines follow, each of them contains three integers: si, fi, ti (1≤si,fi,ti≤109,si<fi) − the description of the buses. It is guaranteed that all ti-s are different.

Then m lines follow, each of them contains three integers: li, ri, bi (1≤li,ri,bi≤109,li<ri) − the Bertown citizens' description. Some bi-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.

Examples
Input
4 3
1 10 10
5 6 2
6 7 3
5 7 4
5 7 1
1 2 1
1 10 11
Output
4 1 -1
Input
1 1
1 1000000000 1000000000
1 1000000000 1000000000
Output
1

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 2608 题。保留原作者与原赛事署名。