{"problem":{"name":"[GDCPC 2023] Swapping Operation","description":{"content":"Given a non-negative integer sequence $A = a_1, a_2, \\dots, a_n$ of length $n$, define $$ F(A)=\\max\\limits_{1\\leq k<n} ((a_1 \\,\\&\\, a_2 \\,\\&\\, \\cdots \\,\\&\\, a_k)+(a_{k+1} \\,\\&\\, a_{k+2} \\,\\&\\, \\cdots","description_type":"Markdown"},"platform":"Luogu","limit":{"time_limit":1000,"memory_limit":1048576},"difficulty":{"LuoguStyle":"P6"},"is_remote":true,"is_sync":true,"sync_url":null,"sign":"LGP9696"},"statements":[{"statement_type":"Markdown","content":"Given a non-negative integer sequence $A = a_1, a_2, \\dots, a_n$ of length $n$, define\n\n$$\nF(A)=\\max\\limits_{1\\leq k<n} ((a_1 \\,\\&\\, a_2 \\,\\&\\, \\cdots \\,\\&\\, a_k)+(a_{k+1} \\,\\&\\, a_{k+2} \\,\\&\\, \\cdots \\,\\&\\, a_n))\n$$\n\nwhere $\\&$ is the bitwise-and operator.\n\nYou can perform the swapping operation at most once: choose two indices $i$ and $j$ such that $1\\leq i < j\\leq n$ and then swap the values of $a_i$ and $a_j$.\n\nCalculate the maximum possible value of $F(A)$ after performing at most one swapping operation.\n\n## Input\n\nThere are multiple test cases. The first line of the input contains an integer $T$ indicating the number of test cases. For each test case:\n\nThe first line contains an integer $n$ ($2\\leq n\\leq 10^5$) indicating the length of sequence $A$.\n\nThe second line contains $n$ integers $a_1, a_2, \\cdots, a_n$ ($0\\leq a_i\\leq 10^9$) indicating the given sequence $A$.\n\nIt's guaranteed that the sum of $n$ of all test cases will not exceed $10^5$.\n\n## Output\n\nFor each test case output one line containing one integer indicating the maximum possible value of $F(A)$ after performing at most one swapping operation.\n\n[samples]\n\n## Note\n\nFor the first sample test case, we can swap $a_4$ and $a_6$ so the sequence becomes $\\{6, 5, 4, 6, 5, 3\\}$. We can then choose $k = 5$ so that $F(A) = (6 \\,\\&\\, 5 \\,\\&\\, 4 \\,\\&\\, 6 \\,\\&\\, 5) + (3) = 7$.\n\nFor the second sample test case, we can swap $a_2$ and $a_4$ so the sequence becomes $\\{1, 1, 1, 2, 2, 2\\}$. We can then choose $k = 3$ so that $F(A) = (1 \\,\\&\\, 1 \\,\\&\\, 1) + (2 \\,\\&\\, 2 \\,\\&\\, 2) = 3$.\n\nFor the third sample test case we do not perform the swapping operation. We can then choose $k = 2$ so that $F(A) = (1 \\,\\&\\, 1) + (2 \\,\\&\\, 2 \\,\\&\\, 2) = 3$.","is_translate":false,"language":"English"}],"meta":{"iden":"LGP9696","tags":["2023","广东","O2优化","前缀和","省赛/邀请赛"],"sample_group":[["3\n6\n6 5 4 3 5 6\n6\n1 2 1 1 2 2\n5\n1 1 2 2 2","7\n3\n3"]],"created_at":"2026-03-03 11:09:25"}}