Kamui
시간 제한2초메모리 제한1024 MB
차수를 배열로 유지하면서 한 원소씩 늘리거나 줄이는 질의마다 이분 그래프에 생기는 길이 4 사이클의 개수를 구한다.
문제
There is a graph with a total of vertices. There are no edges between the st and -th vertices, and there are no edges between the -th and -th vertices. That is, the given graph is a bipartite graph.
A sequence of positive integers is given. For any pair with , the necessary and sufficient condition for vertices and to be connected is that .
A total of queries are given. Each query is represented by two integers and , indicating that the value of will be changed to . It is guaranteed that or . For each query, you must count the number of cycles of length in the given graph. Since the count may be large, output the remainder when divided by . Two cycles are considered different if the sets of edges composing them are different.
입력
The first line contains two positive integers and , separated by a space.
The second line contains a total of integers , separated by spaces.
The next lines each contain two integers and separated by a space. The input on the th line indicates that will be changed to .
출력
After each query is executed, output the remainder when the number of cycles of length is divided by on each line.
제한
- ,
- For each queries, and x \in \left\\{ -1, 1 \right\\}.
- After each queries, it is guaranteed that for all .
힌트
The set of four edges \left\\{ xy,yz,zw,wx\right\\} in a graph is considered to be a cycle of length .