当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

如何提高员工积极性?

知乎高赞:拼多多和国家电网,选哪个?

Copycat CNN: Stealing Knowledge by Persuading Confession with Random Non-Labeled Data阅读心得
The second step through MySQL in four steps: MySQL index learning

Hubei Mobile HG680-LV_S905L3B_wire brush firmware package

浅谈运用低代码技术如何实现物流企业的降本增效

Analysis of the gourd baby

MySQL学习笔记-4.数据更新时的性能问题

How to convert an int attribute into a string in the json format returned by the Go language gin framework?

【LeetCode每日一题】——540.有序数组中的单一元素
随机推荐
【商家联盟】云平台—异业联盟,打造线上线下商业相结合的系统
(1), the sequential storage structure of linear table chain storage structure
学习探索-给字体设置前景色
R语言使用yardstick包的gain_curve函数评估多分类(Multiclass)模型的性能、查看模型在多分类每个分类上的增益(gain)曲线(gain curve)
Codeforces Round #811 (Div. 3)
码蹄集 - MT2142 - 万民堂大厨
【Gazebo入门教程】第二讲 模型库导入与可视化机器人建模(模型编辑器)
Nacos集群搭建
Hubei Telecom Tianyi TY1608_S905L3B_MT7668_ card brush firmware package
88.(cesium之家)cesium聚合图
消灭异步回调,还得是async-await
Copycat CNN: Stealing Knowledge by Persuading Confession with Random Non-Labeled Data阅读心得
LeetCode Question of the Day - 1403. Minimum Subsequence in Non-Increasing Order
西西成语接龙小助手
CSDN21天学习挑战赛——程序流程控制(02)
response的contentType 几种类型
Learning to Explore - Setting the Foreground Color for Fonts
Mobile magic box CM201-1_CW_S905L2_MT7668_wire brush firmware package
Flutter实战-请求封装(四)之gzip报文压缩
SAP 电商云 Spartacus UI 页面布局的设计原理