Under construction

Still being built. Things may change

Lecture Room Reservation System

Interview

Time limit1sMemory limit1024 MB

Summary
Given reservation requests sorted by start time, decide for each whether it overlaps an accepted booking in the same room and print YES or NO.
Level

Easy3 of 10

Topics
Array, Greedy, Implementation
Solved
No attempts yet

Problem

Chungnam National University's Engineering Building 5 has NN lecture rooms numbered from 11 to NN. Students reserve a room through the reservation system before using it. To reserve a room, a student sends the room number kk, a start time ss, and an end time ee to the system.

One day, the system receives MM reservation requests. The requests arrive in order of start time ss from earliest to latest, and no two requests share the same start time. The system checks the requests in order. If a request does not overlap any reservation already accepted for the same room, the system accepts it. Otherwise, it rejects it. Two reservations where one ends at the exact time the other starts do not overlap.

Given the MM requests, determine whether the system accepts or rejects each one.

Input

The first line contains integers NN and MM (1≤N,M≤200 0001 \le N, M \le 200\,000).

Each of the next MM lines contains a room number kik_i (1≤ki≤N1 \le k_i \le N) and integers sis_i and eie_i (1≤si<ei≤1091 \le s_i < e_i \le 10^9), the start and end times of the ii-th reservation. The reservations are given in ascending order of ss, and no two share the same start time.

Output

Print MM lines. For each request in order, print YES if the system accepts it, or NO if it rejects it.

Hint

Slow input and output can cause a time limit exceeded when reading or printing many lines.

If you use C++ with cin and cout, apply both cin.tie(NULL) and sync_with_stdio(false), and write \n instead of endl. After this, do not use C-style I/O such as scanf, printf, puts, getchar, or putchar.

If you use Java, you can use BufferedReader and BufferedWriter instead of Scanner and System.out.println. Call BufferedWriter.flush only once, at the end.

If you use Python, you can use sys.stdin.readline instead of input. It keeps the trailing newline, so call .rstrip() when you store a string.

Examples2

  1. Example 1

    Input
    1 3
    1 2 3
    1 3 5
    1 4 6
    
    Expected output
    YES
    YES
    NO
    
  2. Example 2

    Input
    2 4
    1 1 4
    2 2 5
    1 3 7
    1 5 8
    
    Expected output
    YES
    YES
    NO
    YES