6990: Sequence II

时间限制: 3 Sec  内存限制: 128 MB
提交: 206  解决: 23
[提交][状态][讨论版][命题人:admin]

题目描述

We define an element ai in a sequence "good", if and only if there exists a j(1≤ j < i) such that aj < ai.
Given a permutation p of integers from 1 to n. Remove an element from the permutation such that the number of "good" elements is maximized.

 

输入

The input consists of several test cases. The first line of the input gives the number of test cases, T(1≤ T≤ 10^3).
For each test case, the first line contains an integer n(1≤ n≤ 10^6), representing the length of the given permutation.
The second line contains n integers p1,p2,\cdots,pn(1≤ pi≤ n), representing  the given permutation p.
It’s guaranteed that Σn≤ 2× 10^7.

 

输出

For each test case, output one integer in a single line, representing the element that should be deleted. If there are several answers, output the minimal one.

样例输入

2
1
1
5
5 1 2 3 4

样例输出

1
5
骚的输入操作,用scanf()居然超时!

#include <bits/stdc++.h>
using namespace std;
int scan()
{
int res=0;
char ch;
ch=getchar();
if(ch>='0' && ch<='9')
{
res=ch-'0';
}
while((ch=getchar())>='0' && ch<='9')
{
res=res*10+ch-'0';
}
return res;
}
void out(int a)
{
if(a>9)
{
out(a/10);
}
putchar(a%10+'0');
}
int b[1000100];
int a[1000100];
int main()
{
int t,n,rr,zxz,minn,minnn;
t=scan();
while(t--)
{
memset(b,0,sizeof(b));
n=scan();
if(n==1)
{
a[0]=scan();
out(a[0]);
putchar('\n');
}
if(n==2)
{
a[0]=scan();
a[1]=scan();
out(min(a[0],a[1]));
putchar('\n');
}
if(n>=3)
{
for(int i=0; i<=n-1; i++)
{
a[i]=scan();
if(i==1)
{
minnn=min(a[0],a[1]);
minn=max(a[0],a[1]);
if(a[0]<a[1])
{
b[a[0]]++;
b[a[1]]++;
}
}
else if(i>1)
{
if(a[i]<minnn)
{
minn=minnn;
minnn=a[i];
}
else if(a[i]>minnn && a[i]<minn)
{
b[minnn]++;
b[a[i]]++;
minn=a[i];
}
else if(a[i]>minn)
{
b[a[i]]++;
}
}
}
rr=1e9+7;
zxz=1e9+7;
for(int i=0;i<=n-1;i++)
{
if(b[a[i]]<zxz)
{
zxz=b[a[i]];
rr=a[i];
}
else if(b[a[i]]==zxz && a[i]<rr)
{
rr=a[i];
}
}
out(rr);
putchar('\n');
}
}
return 0;
}

Sequence II的更多相关文章

  1. HDU 5919 Sequence II 主席树

    Sequence II Problem Description   Mr. Frog has an integer sequence of length n, which can be denoted ...

  2. HDU 5919 Sequence II(主席树+逆序思想)

    Sequence II Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

  3. HDOJ 5147 Sequence II 树阵

    树阵: 每个号码的前面维修比其数数少,和大量的这后一种数比他的数字 再枚举每一个位置组合一下 Sequence II Time Limit: 5000/2500 MS (Java/Others)    ...

  4. bestcoder#23 1002 Sequence II 树状数组+DP

    Sequence II Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. hdu 5147 Sequence II 树状数组

    Sequence II Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Prob ...

  6. hdu 5147 Sequence II (树状数组 求逆序数)

    题目链接 Sequence II Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. [HDU5919]Sequence II

    [HDU5919]Sequence II 试题描述 Mr. Frog has an integer sequence of length n, which can be denoted as a1,a ...

  8. hdu 5147 Sequence II【树状数组/线段树】

    Sequence IITime Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...

  9. HDU 5919 -- Sequence II (主席树)

    题意: 给一串数字,每个数字的位置是这个数第一次出现的位置. 每个询问对于序列的一个子区间,设一共有k个不同的数,求第ceil(k/2)个数的位置. 因为强制在线,所以离线乱搞pass掉. 主席树可解 ...

随机推荐

  1. iptable学习

    参考文档 朱双印个人日志 netfilter/iptables架构 位置 钩子函数/规则链 说明 数据包刚刚进入网络层的位置 PREROUTING 在这里处理目标地址转换 经过路由判断,数据包从内核流 ...

  2. MATLAB实现回归分析

    下面是一道例题

  3. PHP 数字补零 固定位数补0

    在处理订单编号的时候,需要固定位数的数字,比如需要固定四位数格式: 1->0001 56->0056 288->0288 1992->1992 可以使用php内置函数str_p ...

  4. 记录错误:tomcat“socket close”错误

    Error running 'Tomcat 8.5.37': Unable to open debugger port (127.0.0.1:9562) 使用打开cmd.exe 输入 1)taskli ...

  5. python基本数据类型2——操作

    字符串 name = "alex" # 移除两边的空格 print(name.strip()) #strip不修改值 # 是否以"al"开头 print(nam ...

  6. Educational Codeforces Round 66 (Rated for Div. 2) B. Catch Overflow!

    链接:https://codeforces.com/contest/1175/problem/B 题意: You are given a function ff written in some bas ...

  7. 洛谷2414(构建ac自动机fail树dfs序后遍历Trie树维护bit及询问答案)

    要点 这是一道蔡队题,看我标题行事 任意询问y串上有多少个x串,暴力找每个节点是不是结尾肯定是炸的,考虑本质:如果某节点是x的结尾,根据ac自动机的性质,x一定是此(子)串后缀.又有每个Trie节点的 ...

  8. Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) A

    Arpa is researching the Mexican wave. There are n spectators in the stadium, labeled from 1 to n. Th ...

  9. ZipUtils

    package com.yundaex.common.exception.util; import java.io.ByteArrayInputStream; import java.io.ByteA ...

  10. NET Core的分布式批处理框架

    NET Core的分布式批处理框架 Swift是什么 从文章的标题可知:此Swift非Apple那个Swift,只是考虑这个词的含义比较适合. Swift是一个基于.NET Core的分布式批处理框架 ...