Under construction

Still being built. Things may change

Exam

Time limit3sMemory limit1024 MB

Summary
For each of Q threshold triples, count students with S>=X, T>=Y, and S+T>=Z, where N and Q reach 100000.
Level

Hard8 of 10

Topics
Sorting, Prefix sum, Binary search, Geometry
Solved
No attempts yet

Problem

NN students took an exam with a mathematics section and an informatics section. The ii-th student (1≤i≤N1 \le i \le N) scored SiS_i points in mathematics and TiT_i points in informatics. Professor T and Professor I want to decide, based on the scores, whether each student passes the exam.

  • Professor T cares about both subjects. A student passes only if they score at least AA points in mathematics and at least BB points in informatics.
  • Professor I cares only about the total score. A student passes if their mathematics and informatics scores sum to at least CC points.
  • A student passes the exam only if they satisfy both professors' criteria.

You do not know the thresholds AA, BB, CC. Instead, you are given QQ triples of integers (Xj,Yj,Zj)(X_j, Y_j, Z_j) (1≤j≤Q1 \le j \le Q), and you want to know how many students pass the exam when A=XjA=X_j, B=YjB=Y_j, C=ZjC=Z_j.

Given the students' scores and the score thresholds, find the number of students who pass the exam under these conditions.

Input

The input is given in the following format from standard input. All values are integers.

NN QQ S1S_1 T1T_1 ⋮\vdots SNS_N TNT_N X1X_1 Y1Y_1 Z1Z_1 ⋮\vdots XQX_Q YQY_Q ZQZ_Q

Output

Print QQ lines to standard output. The jj-th line (1≤j≤Q1 \le j \le Q) is the number of students who pass the exam when A=XjA=X_j, B=YjB=Y_j, C=ZjC=Z_j.

Constraints

  • 1≤N≤100 0001 \le N \le 100\ 000.
  • 1≤Q≤100 0001 \le Q \le 100\ 000
  • 0≤Si≤1 000 000 0000 \le S_i \le 1\ 000\ 000\ 000 (1≤i≤N1 \le i \le N).
  • 0≤Ti≤1 000 000 0000 \le T_i \le 1\ 000\ 000\ 000 (1≤i≤N1 \le i \le N).
  • 0≤Xj≤1 000 000 0000 \le X_j \le 1\ 000\ 000\ 000 (1≤j≤Q1 \le j \le Q).
  • 0≤Yj≤1 000 000 0000 \le Y_j \le 1\ 000\ 000\ 000 (1≤j≤Q1 \le j \le Q).
  • 0≤Zj≤2 000 000 0000 \le Z_j \le 2\ 000\ 000\ 000 (1≤j≤Q1 \le j \le Q).

Examples2

  1. Example 1

    Input
    5 4
    35 100
    70 70
    45 15
    80 40
    20 95
    20 50 120
    10 10 100
    60 60 80
    0 100 100
    
    Expected output
    2
    4
    1
    1
    
  2. Example 2

    Input
    10 10
    41304 98327
    91921 28251
    85635 59191
    30361 72671
    28949 96958
    99041 37826
    10245 2726
    19387 20282
    60366 87723
    95388 49726
    52302 69501 66009
    43754 45346 3158
    25224 58881 18727
    7298 24412 63782
    24107 10583 61508
    65025 29140 7278
    36104 56758 2775
    23126 67608 122051
    56910 17272 62933
    39675 15874 117117
    
    Expected output
    1
    3
    5
    8
    8
    3
    3
    3
    5
    6