传送门

文章目录

  • 题意:
  • 思路:

题意:

思路:

首先有一个显然的性质就是每组操作最多不会超过两次。
很容易想到一个很暴力的思路,就是枚举x∈[1,2∗k]x \in [1,2*k]x∈[1,2∗k],让后判断一下每组需要操作几次取最小值。这样复杂度O(nk)O(nk)O(nk),显然不能接受。
考虑反方向,通过枚举nnn,来判断对每个iii来说,如果最终变成xxx要操作多少次,分以下三种情况:
(1)x=a[i]+a[n−i+1](1) x=a[i]+a[n-i+1](1)x=a[i]+a[n−i+1],显然操作000次即可。
(2)x∈[min(a[i],a[n−i+1])+1,max(a[i],a[i+1])+k](2) x \in [min(a[i],a[n-i+1])+1,max(a[i],a[i+1])+k](2)x∈[min(a[i],a[n−i+1])+1,max(a[i],a[i+1])+k],操作一次即可。
(3)(3)(3)其余情况操作222次。
以上区间加操作显然可以用差分来实现。
复杂度O(n)O(n)O(n)。

// Problem: D. Constant Palindrome Sum
// Contest: Codeforces - Codeforces Round #636 (Div. 3)
// URL: https://codeforces.com/contest/1343/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n,k;
int a[N],ans[N];
// a[i]+a[n-i+1] --
// [min(a[i],a[n-i+1])+1,max(a[i],a[n-i+1])+k] --int solve() {for(int i=1;i<=k*2;i++) ans[i]=0;ans[1]=n;for(int i=1;i<=n/2;i++) {int mi=min(a[i],a[n-i+1]),mx=max(a[i],a[n-i+1]);ans[a[i]+a[n-i+1]]--; ans[a[i]+a[n-i+1]+1]++;ans[mi+1]--; ans[mx+k+1]++;}int res=INF;for(int i=1;i<=2*k;i++) ans[i]+=ans[i-1],res=min(res,ans[i]);return res;
}int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);int _; scanf("%d",&_);while(_--) {scanf("%d%d",&n,&k);for(int i=1;i<=n;i++) scanf("%d",&a[i]);printf("%d\n",solve());}return 0;
}
/**/

Codeforces Round #636 (Div. 3) D. Constant Palindrome Sum 思维 + 差分相关推荐

  1. Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum

    Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum 题目链接 You are given an array a consisting of ...

  2. Codeforces Round #636 (Div. 3)D. Constant Palindrome Sum

    传送门-链接 题意:输入一个n和k,第二行输入一个长度为n的数组a,且保证了n为一个偶数,数组a中的每一个元素都不大于k,你可以修改多次,使得a[i]+a[n-i+1]=x(x为某个确定的值),你需要 ...

  3. CodeForces - 1343D Constant Palindrome Sum(思维+差分数组)

    题目链接:点击查看 题目大意:给出 n 个数,保证 n 是偶数,且每个数的范围都在 [ 1 , k ] 之间,现在问我们至少需要给多少个数重新赋值,使得可以满足条件: 所有的数的值域都在 [ 1 , ...

  4. Codeforces Round #636 (Div. 3)部分题解

    链接:Codeforces Round #636 (Div. 3) A - Candies 题意:求出一个x满足x+2∗x+4∗x+⋯+2k−1∗x=n且k>1 思路:提出x得x∗(1+2+4+ ...

  5. Codeforces Round #636 (Div. 3)

    Codeforces Round #636 (Div. 3)(2020.4.21) A.Candies 因为题目保证了有解,所以我们枚举一下 k k k就行了. #include <bits/s ...

  6. Codeforces Round #636 (Div. 3) F. Restore the Permutation by Sorted Segments 思维 + 暴力

    传送门 文章目录 题意: 思路: 题意: n≤200n\le200n≤200 思路: 首先关注到rrr从[2,n][2,n][2,n]都出现一次,所以很明显最后一个位置只出现一次,但是这样倒着来不是很 ...

  7. Codeforces Round #636 (Div. 3) E. Weights Distributing 思维 + bfs

    传送门 文章目录 题意: 思路: 题意: n≤2e5,m≤2e5n\le2e5,m\le2e5n≤2e5,m≤2e5 思路: 怎么感觉每场div3div3div3都有一个巧妙的图论题. 首先如果只有两 ...

  8. Codeforces Round #636 (Div. 3) C.Alternating Subsequence

    Codeforces Round #636 (Div. 3) C.Alternating Subsequence 题目链接 Recall that the sequence b is a a subs ...

  9. Codeforces Round #636 (Div. 3) 题解

    A. Candies 查看题解 数学 B. Balanced Array 查看题解 数学 C. Alternating Subsequence 查看题解 贪心 D. Constant Palindro ...

最新文章

  1. 联系 Contact
  2. java thread 输出结果_大神来看看这段程序输出结果是什么?
  3. java statement 存储过程_Java+sql server+CallableStatement调用存储过程三种情况 (转)...
  4. 产品迭代的节奏怎样适应需求的变化?
  5. python爬取拉勾网_python爬虫—爬取拉钩网
  6. Android 获取人民币符号
  7. 中央推进城镇化建设 六行业分享25万亿蛋糕
  8. 孤独星球android app,《孤独星球》终于出了全套免费的旅行指南APP!
  9. php微信上传图文素材,php使用curl 上传微信公共平台素材文件
  10. PROC FORMAT过程
  11. Improving Few-Shot Learning with Auxiliary Self-Supervised Pretext Tasks(论文解读)
  12. UNITY NGUI IPHONEX完美适配
  13. visio的替代工具 - draw.io
  14. 如何高效访问OneDrive个人存储空间?三种方法
  15. 淘宝网店装修教程模版素材链接
  16. [CF1039E]Summer Oenothera Exhibition[根号分治+lct]
  17. 图像分类在乳腺癌检测中的应用
  18. 番茄工作法总结-第一章:一次只做一件事
  19. 光驱全介绍(包括dvd-supermulti rambo cambo)
  20. python中mainloop什么意思_Tkinter中的mainloop应该如何理解?

热门文章

  1. 在计算机技术方面用英语怎么说,“计算机应用技术”用英语怎么说?
  2. css实战手册第四版 pdf_你真的了解CSS继承吗?看完必跪
  3. 怎样分辨谁才是朋友圈里的真·贵族?
  4. 竞赛奇葩队名,学编程的人都是隐藏的段子手 | 今日最佳
  5. 公司重金求数据分析师:为什么90%的公司都需要它?
  6. 如何用matlab消除谐波,如何在含有整次谐波和非整次谐波的信号中去除整次谐波?...
  7. 截获android屏幕服务,如何捕获android设备屏幕内容?
  8. php 结构体_php基础知识集合
  9. office连接oracle,Access(VBA)连接Oracle数据库的代码
  10. u盘安全删除 linux,为什么要安全删除U盘