1241 : 二合一
时间限制Time Limit
1
秒Sec
内存限制Memory Limit
512
兆MB
提交次数Submitted
359 次Times
通过次数Solved
118 次Times
标准评测 Standard
从标准输入读入,结果写到标准输出。评测将输出拆成 token,与标准答案逐项比较,不按整段逐字节比对。
Read from standard input and write to standard output. The judge splits the output into tokens and compares them with the official answer; it does not compare raw bytes.
| 比对Compare | token 相同即通过。中间的空格、制表符、换行可多可少。Matching tokens pass. Extra spaces, tabs, or newlines between them are ignored. |
|---|---|
| 不同则错Differs | token 个数或内容不同即错误。23 与 2 3、02 与 2、2.0 与 2 均视为不同。A different token count or value is wrong. 23 vs 2 3, 02 vs 2, and 2.0 vs 2 all differ. |
| 输入Input | 标准输入,格式见题面。Standard input; format as in the statement. |
| 输出Output | 标准输出。Standard output. |
题目描述Description
这是一道二合一题。
给定一个长度为 \(n\) 的颜色序列 \(c_1,\cdots, c_n (1 \le c_i \le n)\)。
对于 \(1 \le x \le n, 1 \le l \le r \le n\),定义 \(\operatorname{occ}(x,l,r)\) 为颜色 \(x\) 在序列 \(c\) 的第 \(l\) 至 \(r\) 项出现的次数。
你需要找到序列的一个区间 \([l,r]\),再找到两种颜色 \(x,y\)(注意 \(x,y\) 可以相等),使得 \[\operatorname{occ}(x,l,r) \mathop{\mathrm{or}} \operatorname{occ}(y,l,r)\] 最大,其中 \(\mathrm{or}\) 为二进制按位或。你只需要输出这个最大值。
输入格式Input
本题有多组测试数据。第一行一个正整数 \(T\)(\(1\leq T\leq 10^5\)) 表示数据组数。对于每组数据,
- 第一行一个正整数 \(n\)(\(1\leq n\leq 10^5\)),
- 第二行 \(n\) 个整数 \(c_1,\cdots, c_n\) 描述序列 \(c\)(\(1\leq c_i\leq n\))。
保证所有数据中 \(n\) 的和不超过 \(5\times 10^5\)。
输出格式Output
对于每组数据输出一行一个整数表示答案。
样例Sample
提示Hint
【样例解释 #0】
一种选择的方法是选择区间 \([2,5]\),再选择颜色 \(2,3\),出现次数分别为 \(2,1\),按位或的结果为 \(3\),可以证明没有更优的解法。
出题Author
THU