LIS or Reverse LIS?(思维)

LIS or Reverse LIS?

传送门 Problem - 1682C - Codeforces

题意

问一个数列的严格增序列和减序列的较小值的最大值是多少,序列随意排列。

思路

个数为2个的对两个都有1的贡献;个数为1的则两个可以有一个共用;个数超过2的数多出来的没用。

#include <bits/stdc++.h>
typedef long double ld;
typedef long long ll;
#define pb push_back
#define mk make_pair
#define mt make_tuple
#define eb emplace_back
#define pob pop_back
#define rz resize
#define mem(a,b) memset(a,b,sizeof(a))
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define debug(a) cout<<#a<<"="<<a<<endl;
#define xx first
#define yy second
#define qwe(i,a,b) for(int i=a;i<=b;i++)
#define ewq(i,a,b) for(int i=a;i>=b;i--)
inline ll rr(){ll f=1,x=0;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');return f*x;}
using namespace std;
const ll INF=0x3f3f3f3f,inf=0x3f3f3f3f3f3f3f;
const ll mod[2]={int(1e9 + 7), 10007};
const int base[2]={29,31};
const int maxn=2e5+6;
ll qpow(ll x,ll n){ll ans=1;while(n>0){if(n&1)ans=ans*x%mod[1];x=x*x%mod[1];n>>=1;}return ans;}

int n,cnt;
int a[maxn],q[maxn];
void init(/* arguments */) {
    cnt=0;
    n=rr();
    for(int i=0;i<n;i++) a[i]=rr();
}
int main(int argc, char const *argv[]) {
    int t=rr();
    while (t--) {
        init();
        std::map<int,int> mp;
        int sz=n;
        for(int i=0;i<n;i++) {
            mp[a[i]]++;
            if(mp[a[i]]==2) cnt++;
            if(mp[a[i]]>2) sz--;
        }
        int one=sz-(cnt<<1);
        int ans=cnt+(one>>1)+(one&1);
        std::cout << ans << '\n';
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值