QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#6272. 克莱因瓶

统计

给定一个 $(n+1)\times (n+1)$ 的网格图,每个点坐标为 $(i,j)$,其中 $0\leq i,j\leq n$。对于每个 $(i, j)$, - 对于 $j\geq 1$,到 $(i,j-1)$ 有一条双向边,以及 $(i,0)$ 到 $(i,n)$ 有一条双向边。 - 对于 $i\geq 1$,到 $(i-1,j)$ 有一条双向边,以及 $(0,j)$ 到 $\boldsymbol {(n, n-j)}$ 有一条双向边,注意这里 $\boldsymbol j$ 连接到 $\boldsymbol{n-j}$,所以你可以理解成一个克莱因瓶

每次给定克莱因瓶上的两个点,问它们之间的最短路长度。

输入格式

第一行输入两个正整数 $n,q$。

接下来 $q$ 行每行输入四个整数 $x_1,y_1,x_2,y_2$,表示两个点的坐标分别为 $(x_1,y_1)$ 和 $(x_2,y_2)$。

输出格式

输出 $q$ 行,按顺序输出询问对应的答案。

样例数据

样例 1 输入

10 5
1 9 10 1
7 4 5 4
1 1 3 1
6 6 0 2
10 2 6 1

样例 1 输出

2
2
2
7
5

子任务

对 $100\%$ 的数据,保证 $1\leq n\leq 10^8$,$1\leq q\leq 10^5$,$0\leq x_1,y_1,x_2,y_2\leq n$。

对于测试点 $1\sim 3$,保证 $n,q\leq 10$。

对于测试点 $4\sim 5$,保证 $n\leq 10$。

对于测试点 $6\sim 7$,保证 $n\leq 10^3$。

对于测试点 $8\sim 9$,保证 $q=1$。

对于测试点 $10$,无特殊限制。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.