就是我这个菜鸡,赛时写出了 E2 的做法,但是算错复杂度,导致以为自己的做法只能AC E1,就没交到 E2 上,然后赛后秒A.....

题意

定义一种字串为形如:\([\underbrace{a, a, \dots, a}_{x}, \underbrace{b, b, \dots, b}_{y}, \underbrace{a, a, \dots, a}_{x}]\)

问你在给定的字串中,符合这种要求的最大子序列(可以不连续)的长度

给出数列长度 \(n\le 2\cdot 10^5\),数列中每个数 \(a_i\le 200\)


考虑暴力枚举 \(a\),然后对于每一个 \(a\),枚举 \(x\),也就是两边的 \(a\) 的 个数

用两个 vector,分别记录从前和从后数,第 \(x\) 个 \(a\) 的位置

然后一直枚举到第 \(\lfloor\dfrac{\text{a出现的次数}}{2}\rfloor\) 个

此时,再暴力枚举 \(b\),记录一个前缀和 \(sum_{b,i}\),表示 \(b\) 这个数,在前 \(i\) 位中出现的次数

假设在 vector 中记录的整数第 \(x\) 个 \(a\) 的位置是 \(pos1\),倒数第 \(x\) 个位置是 \(pos2\),那么中间 \(b\) 的个数就是 \(sum_{b,pos2}-sum_{b,pos1-1}\)

然后给所有枚举到的 \(b\) 取一个 \(\max\) 就行

注意在 \(pos1,pos2\) 中,要分别先 push_back 一个 \(0\) 和 \(n+1\),意思是正数倒数第 \(0\) 第出现的位置,同时方便后面的枚举

每枚举一个 \(a\),设它出现的次数为 \(num_a\),则它的复杂度为 \(200\times num_a\)

那么总复杂度是 \(\sum_{i=1}^{200}num_a\times 200=200\times n\)

赛时没想到这点导致并没有交 E2 qaq

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<iomanip>
#include<vector>
#include<cstring>
#define reg register
#define EN std::puts("")
#define LL long long
inline int read(){
register int x=0;register int y=1;
register char c=std::getchar();
while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
return y?x:-x;
}
int sum[206][200006];
std::vector<int>pos1[206],pos2[206];
int num[206];
int a[200006];
int main(){int T=read();while(T--){
// std::printf("%lld",sizeof sum+sizeof pos1+sizeof pos2+sizeof a);
int n=read();
for(reg int i=1;i<=200;i++){
pos1[i].clear();pos2[i].clear();
pos1[i].push_back(0);pos2[i].push_back(n+1);
}
for(reg int x,i=1;i<=n;i++){
for(x=1;x<=200;x++) sum[x][i]=sum[x][i-1];
a[i]=read();sum[a[i]][i]++;
num[a[i]]++;pos1[a[i]].push_back(i);
}
for(reg int i=n;i;i--) pos2[a[i]].push_back(i);
reg int ans=0;
for(reg int a=1;a<=200;a++){
for(reg int x=0;x<=num[a]>>1;x++){
for(reg int b=1;b<=200;b++)
ans=std::max(ans,(x<<1)+sum[b][pos2[a][x]-1]-sum[b][pos1[a][x]]);
}
}
std::printf("%d\n",ans);
std::memset(num,0,sizeof num);
for(reg int x,i=1;i<=n;i++){
for(x=1;x<=200;x++) sum[x][i]=0;
}
}
return 0;
}

CF1335E Three Blocks Palindrome的更多相关文章

  1. Three Blocks Palindrome (easy version)[暴力-预处理]

    给定一个数组,找出最长的子序列,满足 a,a,..a,b,b,..b,a,a,..a 前面的a和后面的a都要是x个,中间的b是y个. 其中,x>=0且y>=0. \(\color{Red} ...

  2. Codeforces Round #634 (Div. 3)

    D题想复杂了,花了好多时间,感觉也没时间看F了,就来写个题解蹭蹭访问量把^_^ 传送门:1335 A. Candies and Two Sisters 题意:你要把n个糖果分给两个人,两个人的糖果数不 ...

  3. HDU 4618 Palindrome Sub-Array (2013多校2 1008 暴力)

    Palindrome Sub-Array Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Oth ...

  4. HDU 4618 Palindrome Sub-Array 暴力

    Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ...

  5. Joining Byte Blocks(哈希+带花树)

    题目链接 Problem Statement As you are probably aware, the Internet protocols specify a canonical byte or ...

  6. 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM

    刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...

  7. PALIN - The Next Palindrome 对称的数

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  8. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  9. [LeetCode] Palindrome Pairs 回文对

    Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...

随机推荐

  1. Linux 磁盘管理篇(一 磁盘分区)

    显示系统所有分区内容            fdisk 分区工具                parted fdisk: 执行完后按下 q 是退出不保存操作的意思 执行完后按下 w 是执行操作的意思 ...

  2. Flutter 吐血整理组件继承关系图

    老孟导读:前几天一个读者和我说能不能整理一个各个控件之间的继承关系,这2天抽时间整理了一下,不整理不知道,一整理真的吓一跳啊,仅仅Widget的子类(包括间接子类)就高达353个,今天发群里给大家浏览 ...

  3. AJ学IOS(43)之网易彩票底部自定义TabBar实现切换

    AJ分享,必须精品 效果: 代码: NYTabBarController // // NYTabBarController.m // 彩票lottery // // Created by apple ...

  4. 2020不平凡的90天,Python分析三个月微博热搜数据带你回顾

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:刘早起早起 PS:如有需要Python学习资料的小伙伴可以加点击下方链 ...

  5. 落谷 P1734 最大约数和

    题目描述 选取和不超过S的若干个不同的正整数,使得所有数的约数(不含它本身)之和最大. 输入格式 输入一个正整数S. 输出格式 输出最大的约数之和. 输入输出样例 输入 #1复制 11 输出 #1复制 ...

  6. 腾讯云集群服务部署mysql并挂载到服务器

    一.背景 由于现在大部分的应用都是运行在云服务器上的,而现在大多数文章都是主要写如何在服务器上使用docker去运行mysql,比较少有介绍云服务器上的.再加上现在k8s比较火爆,而云厂商大多数都提供 ...

  7. JavaScript基础1228JavaScript:void(0)开始----

    JavaScript:void(0)含义 JavaScript:void(0)含义 我们经常会使用到JavaScript:void(0)这样的代码,那么在JavaScript中JavaScript:v ...

  8. [一道蓝鲸安全打卡Web分析] 文件上传引发的二次注入

    蓝鲸打卡的一个 web 文件上传引发二次注入的题解和思考 蓝鲸文件管理系统 源代码地址:http://www.whaledu.com/course/290/task/2848/show 首先在设置文件 ...

  9. 2019CISCN华南线下两道web复现

    原帖地址 : https://xz.aliyun.com/t/5558 2019CISCN华南线下的两个简单 web 部分题目下载地址,有的不完整 : 点我点我 web 1 考点 : 无参函数的 RC ...

  10. synchronized 代码块怎么用

    加不加 synchronized 有什么区别? synchronized 作为悲观锁,锁住了什么? 之前 2 篇文章我们已经知道 synchronized 的使用方法以及锁的内容(实例对象和Class ...