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. Guid string 转换

    System.Guid.NewGuid().ToString(); //GUID带-分割// db1b98e9-6f93-41aa-84f8-5eb773e93d67System.Guid.NewGu ...

  2. 数据库路由中间件MyCat - 源代码篇(1)

    此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 进入了源代码篇,我们先从整体入手,之后拿一个简单流程前端连接建立与认证作为例子,理清代码思路和设计模式.然后 ...

  3. CentOS 安装Perl环境

    参考博文:https://blog.csdn.net/weixin_40192129/article/details/78610974 vmware tools需要perl环境的支持 安装perl支持 ...

  4. c#---delegate关键字

    http://www.cnblogs.com/wenjiang/archive/2013/03/12/2954913.html 注:只看红字 在C#中,delegate是一个神奇的关键字,值得拿出来单 ...

  5. uoj#279. 【UTR #2】题目交流通道(容斥+数数)

    传送门 先考虑无解的情况,为以下几种:\(dis_{i,j}+dis_{j,k}<dis_{i,k}\),\(dis_{i,i}\neq 0\),\(dis_{i,j}\neq dis_{j,i ...

  6. Luogu P1637 三元上升子序列【权值线段树】By cellur925

    题目传送门 emmm..不开结构体的线段树真香! 首先我们知道"三元上升子序列"的个数就是对于序列中的每个数,**它左边比他小的数*它右边比他大的数**.但是如何快速求出这两个数? ...

  7. Mac下IDEA不能进行编辑

    在安装Idea时,在选择插件的时候,把IDEAVim这个玩意儿选上了. 所以,编辑模式就跟命令行里面的Vim一样.输入时,需要先输入i, 进入insert模式下,然后才可以编辑. 彻底解决办法就是进入 ...

  8. String,StringBuffer和StringBuilder

    String,StringBuffer和StringBuilder分别应该在什么情况下使用? String 是Java的字符串类,其实质上也是用Char类型存储的,但是除了hash属性,其他的属性都声 ...

  9. JMeter(5) JMeter之BeanShell使用

    BeanShell介绍 BeanShell是用Java写成的,一个小型的.免费的.可以下载的.嵌入式的Java源代码解释器,具有对象脚本语言特性.本篇只记录一下基本的使用.有以下五个组件: Beans ...

  10. 题解 [HNOI2002]DNA分子的最佳比对 (洛谷P2268)

    题目传送门 (这道题告诉我:初始化要小心) 有没有一点最长公共子序列的赶脚(口胡) 但我觉得挺像 设 表示匹配到s1的第i位,s2的第j位,则有 的初始化要注意:根据的含义,表示s1[i]一直在匹配空 ...