1.2 KB | 1203 chars
"""
[10598: Knockout Racing](https://www.acmicpc.net/problem/10598)
Tier: Bronze 1
Category: implementation, math
"""
import sys
from math import sqrt, pi, sin, factorial, ceil, floor
from datetime import datetime, timedelta
SYS_INPUT = True
RECURSION_LIMIT = 10 ** 7
SET_RECURSION = False
BLANK = " "
if SET_RECURSION:
sys.setrecursionlimit(RECURSION_LIMIT)
inp = lambda : sys.stdin.readline().rstrip() if SYS_INPUT else input()
mii = lambda : [*map(int,inp().split())]
mfi = lambda : [*map(float,inp().split())]
ii = lambda : int(inp())
fi = lambda : float(inp())
isplit = lambda : inp().split()
p = print
def gcd(a, b): return gcd(b, a % b) if b > 0 else a
def lcm(a, b): return a * b // gcd(a, b)
def solve():
n, m = mii()
l = [mii() for _ in range(n)]
questions = [mii() for _ in range(m)]
for x, y, t in questions:
cnt = 0
for a, b in l:
repeat = t // (b - a)
place = 0
if repeat % 2 == 0:
place = a + t % (b - a)
else:
place = b - t % (b - a)
if x <= place <= y:
cnt += 1
p(cnt)
if __name__ == "__main__":
tc = 1
for t in range(1, tc+1):
ret = solve()