Collinear Arrangements

시간 제한2초메모리 제한2048 MB

요약
각 질의에 대해 한 점과 함께 한 직선 위에 있는 볼록 다각형 꼭짓점 쌍의 개수, 또는 두 점과 함께 한 직선 위에 있는 꼭짓점의 개수를 구한다.
난이도

어려움10점 중 8점

유형
기하, 이분 탐색, 수학, 구현
정답자
아직 제출이 없습니다

문제

Given a convex polygon of nn points P_1,P_2,…,P_nP\_1, P\_2, \ldots, P\_n on a two-dimensional plane, answer qq queries, where each query has one of the following types:

  1. Given one point (x,y)(x, y), find the number of pairs (P_i,P_j)(P\_i, P\_j) such that 1≤i<j≤n1 \le i < j \le n and the three points (x,y)(x, y), P_iP\_i, and P_jP\_j are collinear.
  2. Given two points (x_1,y_1)(x\_1, y\_1) and (x_2,y_2)(x\_2, y\_2), find the number of points P_iP\_i such that 1≤i≤n1 \le i \le n and the three points (x_1,y_1)(x\_1, y\_1), (x_2,y_2)(x\_2, y\_2), and P_iP\_i are collinear.

입력

The first line contains two integers nn and qq (3≤n≤1053 \le n \le 10^5, 1≤q≤1051 \le q \le 10^5) denoting the number of vertices in the given polygon and the number of queries, respectively.

Each of the following nn lines contains two integers, xx and yy, denoting a vertex of the polygon.

Each of the following qq lines contains one query, which is in one of the following formats:

  1. "1 xx yy", asking to calculate the number of pairs (P_i,P_j)(P\_i, P\_j) such that 1≤i<j≤n1 \le i < j \le n and the three points (x,y)(x, y), P_iP\_i, and P_jP\_j are collinear.
  2. "2 x_1x\_1 y_1y\_1 x_2x\_2 y_2y\_2", asking to calculate the number of points P_iP\_i such that 1≤i≤n1 \le i \le n and the three points (x_1,y_1)(x\_1, y\_1), (x_2,y_2)(x\_2, y\_2), and P_iP\_i are collinear.

It is guaranteed that:

  • ∣x∣,∣y∣≤109|x|, |y| \le 10^9 for all points and queries;
  • the polygon vertices are given in counter-clockwise order;
  • the polygon is convex (in particular, no three vertices are collinear);
  • for each query, the given points and the polygon vertices do not coincide;
  • the number of queries in the first format does not exceed 100100.

출력

For each query, output a line containing a single integer: the answer to the query.

힌트

  • For the first query, the only pair is (P_2,P_5)(P\_2, P\_5) since (1,1)(1, 1), P_2=(2,0)P\_2 = (2, 0) and P_5=(0,2)P\_5 = (0, 2) are collinear.
  • For the second query, the only point is P_1P\_1 since (1,1)(1, 1), (2,2)(2, 2), and P_1=(0,0)P\_1 = (0, 0) are collinear.
  • For the third query, the two pairs are (P_2,P_3)(P\_2, P\_3) and (P_4,P_5)(P\_4, P\_5).

예제1

  1. 예제 1

    입력
    5 3
    0 0
    2 0
    2 1
    1 2
    0 2
    1 1 1
    2 1 1 2 2
    1 2 2
    
    예상 출력
    1
    1
    2