当前位置:网站首页>C. LIS or Reverse LIS?
C. LIS or Reverse LIS?
2022-08-04 17:10:00 【秦小咩】
C. LIS or Reverse LIS?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given an array aa of nn positive integers.
Let LIS(a)LIS(a) denote the length of longest strictly increasing subsequence of aa. For example,
- LIS([2,1–,1,3–])LIS([2,1_,1,3_]) = 22.
- LIS([3–,5–,10–––,20–––])LIS([3_,5_,10_,20_]) = 44.
- LIS([3,1–,2–,4–])LIS([3,1_,2_,4_]) = 33.
We define array a′a′ as the array obtained after reversing the array aa i.e. a′=[an,an−1,…,a1]a′=[an,an−1,…,a1].
The beauty of array aa is defined as min(LIS(a),LIS(a′))min(LIS(a),LIS(a′)).
Your task is to determine the maximum possible beauty of the array aa if you can rearrange the array aa arbitrarily.
Input
The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤104)(1≤t≤104) — the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer nn (1≤n≤2⋅105)(1≤n≤2⋅105) — the length of array aa.
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109) — the elements of the array aa.
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.
Output
For each test case, output a single integer — the maximum possible beauty of aa after rearranging its elements arbitrarily.
Example
input
Copy
3 3 6 6 6 6 2 5 4 5 2 4 4 1 3 2 2
output
Copy
1 3 2
Note
In the first test case, aa = [6,6,6][6,6,6] and a′a′ = [6,6,6][6,6,6]. LIS(a)=LIS(a′)LIS(a)=LIS(a′) = 11. Hence the beauty is min(1,1)=1min(1,1)=1.
In the second test case, aa can be rearranged to [2,5,4,5,4,2][2,5,4,5,4,2]. Then a′a′ = [2,4,5,4,5,2][2,4,5,4,5,2]. LIS(a)=LIS(a′)=3LIS(a)=LIS(a′)=3. Hence the beauty is 33 and it can be shown that this is the maximum possible beauty.
In the third test case, aa can be rearranged to [1,2,3,2][1,2,3,2]. Then a′a′ = [2,3,2,1][2,3,2,1]. LIS(a)=3LIS(a)=3, LIS(a′)=2LIS(a′)=2. Hence the beauty is min(3,2)=2min(3,2)=2 and it can be shown that 22 is the maximum possible beauty.
========================================================================
要让最小值最大,也就是正反的LIS尽量差不多大,可以把最大的放在中间,然后大小递减依次排开,也可以把最小的放在中间,但这样一旦出现了大于等于3的元素,就会把我们一边给搞乱,所以直接统计小于等于2次的元素,除以2上取整即可。因为最终贡献每个数最多贡献两次。
# include<bits/stdc++.h>
using namespace std;
# define mod 1000000009
typedef long long int ll;
map<int,int>mp;
int main ()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
mp.clear();
int cnt=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
mp[x]++;
if(mp[x]<=2)
cnt++;
}
int ans=cnt/2;
if(cnt%2)
ans++;
cout<<ans<<'\n';
}
return 0;
}
边栏推荐
猜你喜欢
15 days to upgrade to fight monsters and become a virtual fashion creator
化学制品制造业数智化供应链管理系统:打造智慧供应体系,赋能企业产效提升
移动平台助力推进智慧型科研院所信息化建设
Mobile BesTV_R3300-L_S905L_8189_wire brush firmware package
服装店如何利用好积分?
Clearance sword refers to Offer——The sword refers to Offer II 010. and the sub-array of k
小满nestjs(第一章 介绍nestjs)
MySQL学习笔记-4.数据更新时的性能问题
GraphQL 入门与实践
yarn详细入门教程
随机推荐
WEB 渗透之SSTI 模板注入
Nacos集群搭建
浅谈运用低代码技术如何实现物流企业的降本增效
谷粒商城笔记
Boost library study notes (1) Installation and configuration
罗振宇折戟创业板/ B站回应HR称用户是Loser/ 腾讯罗技年内合推云游戏掌机...今日更多新鲜事在此...
智慧场馆的无人值守怎么做?
AtCoder Beginner Contest 262 部分题解
数字化金融企业的产品体系长啥样?
【Gazebo入门教程】第二讲 模型库导入与可视化机器人建模(模型编辑器)
通关剑指 Offer——剑指 Offer II 010. 和为 k 的子数组
Mobile zte ZXV10 B860AV2. 1 - A_S905L2_MT7668_ wire brush the firmware package
R语言使用yardstick包的gain_curve函数评估多分类(Multiclass)模型的性能、查看模型在多分类每个分类上的增益(gain)曲线(gain curve)
全球电子产品需求萎靡:三星越南工厂大幅压缩产能,减少工人工作日
Selenium Webdriver驱动自管理
arm交叉编译
集群监控——Zabbix使用
dotnet remoting 抛出异常
shell脚本详解 --------循环语句之for循环
GraphQL 入门与实践