cf 600人 bit+大量stl乱搞

Remove Extra One
给出一个排列,问你移除其中那个数,可以使得其中的record最多.
record定义为该数前所有数都小于他.
反正就是一通乱搞把,好笨啊.

/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define gcd __gcd
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MAXM = 5e3+17;


const int MOD = 998244353;
const int MAXN = 1e5+17;
const double EPS = 1e-8;
int bit[MAXN],n;
void add(int x)
{
    while(x<=n)
    {
        bit[x]++;
        x += x&-x;
    }
}
int sum(int x)
{
    int ret = 0;
    while(x>0)
    {
        ret += bit[x];
        x -= x&-x;
    }
    return ret;
}
int a[MAXN],big[MAXN],mx[MAXN],ocr[MAXN];
int main(int argc, char const *argv[])
{
     #ifdef GoodbyeMonkeyKing
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif
    cin>>n;
    //if(n==1) return 0*printf("1\n");
    set<int > rev;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        rev.insert(a[i]);
        mx[i] = a[i];
    }
    for (int i = 0; i < n; ++i)
    {
        if(i)  mx[i] = max(mx[i-1],a[i]);
        add(a[i]);
        big[i] = i - sum(a[i]-1);
        //debug(big[i]);
    }
    //debug(sum(5));
    set<int > s1;
    for (int i = 0; i < n; ++i)
    {
        if(big[i]==0)
        {
            s1.insert(a[i]);
            rev.erase(a[i]);
        }
        if(big[i]==1)
        {
            ocr[mx[i]]++;
        }
    }
    int mxd = 0,ans = INF;
    for (int i = 1; i <= n; ++i)
    {
        //debug(ocr[i]);
        if(ocr[i]>mxd)
        {
            if(ocr[i]==1&&s1.find(i)!=s1.end()) continue;
            mxd = ocr[i];
            ans = i;
        }
        else if(ocr[i]==mxd)
        {
            ans = min(ans,i);
        }
    }
    if(mxd==0)
    {
        if(rev.size())
            cout<<*rev.begin()<<endl;
        else
            cout<<1<<endl;
    }
    else
        cout<<ans<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值