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. jquery获取元素对应高度

    https://www.cnblogs.com/sntetwt/p/3823592.html 获取点击元素距离页面的高度 $(select).offset().top - $(document).sc ...

  2. [Xcode 实际操作]五、使用表格-(11)调整UITableView的单元格顺序

    目录:[Swift]Xcode实际操作 本文将演示如何调整单元格在表格中的位置. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //首先 ...

  3. MyBatis日志实现

    maven项目resources文件夹下log4j.properties 其作用是输出controller包下参与Mybatis的类的SQL语句输出.如果包名不一样,请根据自己的项目情况调整. # G ...

  4. mysql实现rownum方法

    1.语句:SELECT @rownum:=@rownum+1 AS rownum, Orderstate.* FROM (SELECT @rownum:=0) r, Orderstate ; 执行结果 ...

  5. Django之Form组件归类

    目录: Django内置字段 Django内置插件 常用选择插件 创建Form类时,主要涉及到 [字段] 和 [插件],字段用于对用户请求数据的验证,插件用于自动生成HTML; Field requi ...

  6. BZOJ 2288: 【POJ Challenge】生日礼物 堆&&链表

    就是堆+链表,十分像 数据备份 对吧? 把相邻的正数和相邻的负数合并成一整个正数块和负数块,最后只剩一些交替相间的正块与负块了吧? 显然,正块的个数<=m时,全部选走就获得了最大权值,否则我们可 ...

  7. hdu1392凸包裸题

    //极角排序 #include <bits/stdc++.h> #define sqr(x) ((x)*(x)) using namespace std; ],top; struct PO ...

  8. NET Core断点续传

    .NET Core断点续传   ASP.NET Core断点续传 在ASP.NET WebAPi写过完整的断点续传文章,目前我对ASP.NET Core仅止于整体上会用,对于原理还未去深入学习,由于有 ...

  9. Storm概念学习系列之并行度与如何提高storm的并行度

    不多说,直接上干货! 对于storm来说,并行度的概念非常重要!大家一定要好好理解和消化. storm的并行度,可以简单的理解为多线程. 如何提高storm的并行度? storm程序主要由spout和 ...

  10. PHP正则表达式 - 元字符

    下表包含了元字符的完整列表以及它们在正则表达式上下文中的行为: 字符 描述 \ 将下一个字符标记为一个特殊字符.或一个原义字符.或一个 向后引用.或一个八进制转义符.例如,'n' 匹配字符 " ...