{"problem":{"name":"Rectangle GCD","description":{"content":"You are given a positive integer $N$ and sequences of $N$ positive integers each: $A=(A_1,A_2,\\dots,A_N)$ and $B=(B_1,B_2,\\dots,B_N)$. We have an $N \\times N$ grid. The square at the $i$\\-th row from ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc254_f"},"statements":[{"statement_type":"Markdown","content":"You are given a positive integer $N$ and sequences of $N$ positive integers each: $A=(A_1,A_2,\\dots,A_N)$ and $B=(B_1,B_2,\\dots,B_N)$.\nWe have an $N \\times N$ grid. The square at the $i$\\-th row from the top and the $j$\\-th column from the left is called the square $(i,j)$. For each pair of integers $(i,j)$ such that $1 \\le i,j \\le N$, the square $(i,j)$ has the integer $A_i + B_j$ written on it. Process $Q$ queries of the following form.\n\n*   You are given a quadruple of integers $h_1,h_2,w_1,w_2$ such that $1 \\le h_1 \\le h_2 \\le N,1 \\le w_1 \\le w_2 \\le N$. Find the greatest common divisor of the integers contained in the rectangle region whose top-left and bottom-right corners are $(h_1,w_1)$ and $(h_2,w_2)$, respectively.\n\n## Constraints\n\n*   $1 \\le N,Q \\le 2 \\times 10^5$\n*   $1 \\le A_i,B_i \\le 10^9$\n*   $1 \\le h_1 \\le h_2 \\le N$\n*   $1 \\le w_1 \\le w_2 \\le N$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $Q$\n$A_1$ $A_2$ $\\dots$ $A_N$\n$B_1$ $B_2$ $\\dots$ $B_N$\n$\\mathrm{query}_1$\n$\\mathrm{query}_2$\n$\\vdots$\n$\\mathrm{query}_Q$\n\nEach query is in the following format:\n\n$h_1$ $h_2$ $w_1$ $w_2$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc254_f","tags":[],"sample_group":[["3 5\n3 5 2\n8 1 3\n1 2 2 3\n1 3 1 3\n1 1 1 1\n2 2 2 2\n3 3 1 1","2\n1\n11\n6\n10\n\nLet $C_{i,j}$ denote the integer on the square $(i,j)$.\nFor the $1$\\-st query, we have $C_{1,2}=4,C_{1,3}=6,C_{2,2}=6,C_{2,3}=8$, so the answer is their greatest common divisor, which is $2$."],["1 1\n9\n100\n1 1 1 1","109"]],"created_at":"2026-03-03 11:01:14"}}