# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1111777 | Rainmaker2627 | Spiral (BOI16_spiral) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
q=[[[0, -1, 2, 4, 2], [0, 0, 4, 0, 2]], [[0, -4, 10, 0, 2], [0, 1, 2, -4, 2]]]
r=[[[0, 13, 15, 8], [0, 19, -21, 8]], [[0, 19, 21, 8], [0, 13, -15, 8]]]
def p(p, x):
return sum(p[i]*x**i for i in range(len(p)))
def t(x, y):
a,b=x,y
if abs(x)<abs(y): a,b=b,a
c=p(q[x>=0][y>=0], abs(b))
d=abs(b)*(p(r[abs(x)<abs(y)][a>=0],abs(a))-p(r[abs(x)<abs(y)][a>=0],abs(b)))//6
d+=(abs(a)-abs(b))*(abs(b)-(b>=0))*(abs(b)-(b>=0)+1)//2 *(-1 if (abs(x)<abs(y))^(x>=0)^(y>=0) else 1)
if y<0<x and -y<x: d-=8*y
return c+d
mod=10**9+7
n,m=map(int, input().split())
for _ in range(m):
s=0
a,b,c,d=map(int, input().split())
x,y=[a,c+1],[b,d+1]
for i in range(2):
for j in range(2):
s+=t(x[i], y[j])*(-1 if x[0]*x[1]>0 and abs(x[i])<abs(x[1-i]) else 1)*(-1 if y[0]*y[1]>0 and abs(y[j])<abs(y[1-j]) else 1)
print(s%mod)