B. Kalindrome Array
time limit per test1 second
memory limit per test256 megabytes

An array [b1,b2,…,bm] is a palindrome, if bi=bm+1−i for each i from 1 to m. Empty array is also a palindrome.

An array is called kalindrome, if the following condition holds:

It’s possible to select some integer x and delete some of the elements of the array equal to x, so that the remaining array (after gluing together the remaining parts) is a palindrome.

Note that you don’t have to delete all elements equal to x, and you don’t have to delete at least one element equal to x.

For example :

[1,2,1] is kalindrome because you can simply not delete a single element.
[3,1,2,3,1] is kalindrome because you can choose x=3 and delete both elements equal to 3, obtaining array [1,2,1], which is a palindrome.
[1,2,3] is not kalindrome.
You are given an array [a1,a2,…,an]. Determine if a is kalindrome or not.

Input
The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of the array.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n) — elements of the array.

It’s guaranteed that the sum of n over all test cases won’t exceed 2⋅105.

Output
For each test case, print YES if a is kalindrome and NO otherwise. You can print each letter in any case.

Example
input
4
1
1
2
1 2
3
1 2 3
5
1 4 4 1 4
output
YES
YES
NO
YES
Note
In the first test case, array [1] is already a palindrome, so it’s a kalindrome as well.

In the second test case, we can choose x=2, delete the second element, and obtain array [1], which is a palindrome.

In the third test case, it’s impossible to obtain a palindrome.

In the fourth test case, you can choose x=4 and delete the fifth element, obtaining [1,4,4,1]. You also can choose x=1, delete the first and the fourth elements, and obtain [4,4,4].

问题链接:CodeForces - 1610B Kalindrome Array
问题简述:(略)
问题分析:(略)
AC的C++语言程序如下:

/* CodeForces - 1610B Kalindrome Array */#include <bits/stdc++.h>using namespace std;const int N = 200000 + 1;
int a[N], b[N];int main()
{int t;scanf("%d", &t);while (t--) {int n;scanf("%d", &n);for (int i = 1; i <= n; i++) scanf("%d", &a[i]);int x = 0, y = 0;for (int i = 1, j = n; i < j; i++, j--)if (a[i] != a[j]) {x = a[i], y = a[j];break;}int flag = 1;if (x == 0 && y == 0);else {flag = 1;int cnt = 0;for (int i = 1; i <= n; i++)if (a[i] != x) b[cnt++] = a[i];for (int i = 0, j = cnt - 1; i < j; i++, j--)if (b[i] != b[j]) {flag = 0;break;}if ( flag );else {flag = 1;cnt = 0;for (int i = 1; i <= n; i++)if (a[i] != y) b[cnt++] = a[i];for (int i = 0, j = cnt - 1; i < j; i++, j--)if (b[i] != b[j]) {flag = 0;break;}}}printf("%s\n", flag ? "YES" : "NO");}return 0;
}

CodeForces - 1610B Kalindrome Array相关推荐

  1. Codeforces 1054D Changing Array

    Codeforces 1054D Changing Array 做法:给定一个序列,每个数可以把在2进制k位下取反,也可以不变,在改变后,这个序列异或和不为0的区间的个数.考虑如何求出尽可能少的异或为 ...

  2. codeforces EDU suffix array

    本文以codeforces EDU suffix array为资料 content introdcution suffix array height array lcp problems & ...

  3. [codeforces 1343B] Balanced Array 奇+奇=偶,奇+偶=奇,偶+偶=偶

    Codeforces Round #636 (Div. 3)   比赛人数12253 [codeforces 1343B]   Balanced Array   奇+奇=偶,奇+偶=奇,偶+偶=偶 总 ...

  4. CodeForces - 1539F Strange Array(线段树区间合并)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,规定位置 iii 的贡献是:设 x=a[i]x=a[i]x=a[i],选择一个包含 iii 的区间 [l,r][l,r][l,r],将其中 ...

  5. CodeForces - 1534E Lost Array(bfs+交互)

    题目链接:点击查看 题目大意:初始时给出一个长度为 nnn 的序列,每次可以询问 kkk 个位置的异或和,现在需要以最少的询问获得整个序列的异或和 题目分析:因为是异或,我们只关心每个位置被询问的次数 ...

  6. codeforces 1367B - Even Array

    B. Even Array time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...

  7. 【Codeforces】808D Array Division(前后两部分和相等)

    http://codeforces.com/contest/808/problem/D 给你一个数组,问:是否可以通过移动一个数字的位置,求只能移动一次,使得这个数组前后部分的和相等,前后部分不一定等 ...

  8. Codeforces 494D Upgrading Array

    http://codeforces.com/contest/494/problem/D 题意:给一个数组,和一个坏质数集合,可以无数次地让1到i这些所有数字除以他们的gcd,然后要求Σf(a[i])的 ...

  9. CodeForces - 817D Imbalanced Array(单调栈)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,求出所有子区间的最大值与最小值之差的和 题目分析:不难看出最大值和最小值之差的和可以拆开,拆成最大值之和与最小值之和之差,现在问题转换为如 ...

最新文章

  1. GNU parted的指令說明[转]
  2. hdu 1872(稳定排序)
  3. mysql设置常用——修改大小写、设置sql_mode不支持功能、
  4. spring事务(三)
  5. java记事本技术参数_[源码和文档分享]基于JAVA的记事本
  6. mysql binlog2sql_mysql闪回工具binlog2sql安装配置教程详解
  7. 操作系统重装或还原后Domino 8 无法启动解决方法
  8. Trick (六)——随机图的构造
  9. LeetCode 100. Same Tree
  10. 利用SusuCMS快速创建网站(一)
  11. 【数据结构 严蔚敏版】 顺序栈 基本操作
  12. 八皇后-韩顺平java
  13. 距离2022年研究生考试还有多少天?倒计时天数用便签设置
  14. oracle seq nextval,在oracle中使用sequence.nextval创建表
  15. MVC+Echarts绘制统计图表
  16. 计算机桌面的文件拒绝访问,win10系统桌面文件无法重命名提示访问被拒绝的设置办法...
  17. java.util.base64_java.util.Base64
  18. redis 失效时间单位是秒还是毫秒_redis设置过期时间
  19. Github 上火热的十个 Python 项目,从Debug工具到AI水军、量化交易系统。( 嗨学编程)
  20. Summary of Statistics for Interview

热门文章

  1. [JavaME]利用java.util.TimerTask来做Splash Screen的N种方法
  2. 一款免费的网络时间校准小程序
  3. 开源GIS(十一)——openlayers中加载离线标准与自定义切片(深度好文)
  4. nodejs json转对象_nodejs读取xlsx格式文件
  5. otn系统中常用的电层_夏季温室大棚生产中常用的降温系统
  6. Spark解决的问题与体系结构
  7. 永州计算机应用等级,5月永州计算机应用能力考试报名
  8. php_connect_nonb,net2ftp无法显示文件列表输出为空
  9. Android集成JPush(极光推送)
  10. 人生苦短 我用Python