树状数组+离散化

#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std; const int maxn=+;
int a[maxn],ans[maxn],c[maxn],b[maxn];
int n;
map<int,int>m; int lowbit(int x)
{
return x&(-x);
} void update(int a,int b)
{
for(int i=a;i<=n;i=i+lowbit(i)) c[i]+=b;
} int get(int a)
{
int res=;
for(int i=a;i>;i=i-lowbit(i)) res+=c[i];
return res;
} void lsh()
{
sort(b+,b++n);
for(int i=;i<=n;i++) m[b[i]]=i;
} int main()
{
scanf("%d",&n);
int k=;
memset(c,,sizeof c);
m.clear();
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
lsh();
for(int i=;i<=n;i++)
{
if(m[a[i]]==i)
{
int num=get(m[a[i]]-);
if(num==m[a[i]]-) ans[k++]=m[a[i]];
}
update(m[a[i]],);
}
sort(ans,ans+k);
printf("%d\n",k);
for(int i=;i<k;i++)
{
printf("%d",b[ans[i]]);
if(i<k-) printf(" ");
}
printf("\n");
return ;
}

PAT (Advanced Level) 1101. Quick Sort (25)的更多相关文章

  1. 【PAT甲级】1101 Quick Sort (25 分)

    题意: 输入一个正整数N(<=1e5),接着输入一行N个各不相同的正整数.输出可以作为快速排序枢纽点的个数并升序输出这些点的值. trick: 测试点2格式错误原因:当答案为0时,需要换行两次

  2. 1101. Quick Sort (25)

    There is a classical process named partition in the famous quick sort algorithm. In this process we ...

  3. PAT甲题题解-1101. Quick Sort (25)-大水题

    快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...

  4. PAT (Advanced Level) 1114. Family Property (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  5. PAT (Advanced Level) 1109. Group Photo (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  6. PAT (Advanced Level) 1105. Spiral Matrix (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...

  7. PAT (Advanced Level) 1071. Speech Patterns (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  8. PAT (Advanced Level) 1063. Set Similarity (25)

    读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...

  9. PAT (Advanced Level) 1048. Find Coins (25)

    先对序列排序,然后枚举较小值,二分较大值. #include<iostream> #include<cstring> #include<cmath> #includ ...

随机推荐

  1. 【Machine Learning in Action --3】决策树ID3算法

    1.简单概念描述 决策树的类型有很多,有CART.ID3和C4.5等,其中CART是基于基尼不纯度(Gini)的,这里不做详解,而ID3和C4.5都是基于信息熵的,它们两个得到的结果都是一样的,本次定 ...

  2. IAR和Keil文件包含路径设置

    在模块化编程时,为一个模块单独设置头文件是必不可少的. 在两款主流编译器中,在引用模块函数时候,包含头文件路径是必须的,那么设置文件路径的准确性就显得尤为重要. 否则,编译器会报错,无法打开某某头文件 ...

  3. js 手动轮播和自动轮播

    $(function(){ //默认值 $("#carousel1").css("background-color","#FFF"); // ...

  4. 1.5后台修改添加TDK

    manager\includes\languages\english.php //注意 是后台的语言包define('BOX_CONFIGURATION_Lin_STORE', 'TDKcss_set ...

  5. assert()函数用法

    assert是定义在头文件cassert中的宏 其作用是如果他的返回值不为真则终止程序. assert(expression); if 为假,先向stderr打印一条错误信息,再用abort终止程序 ...

  6. 让AutoMapper在你的项目里飞一会儿(转)

    出处:http://www.cnblogs.com/WeiGe/p/3835523.html 先说说DTO DTO是个什么东东? DTO(Data Transfer Object)就是数据传输对象,说 ...

  7. JSON, list, 前台显示

    前台 $(function(){ $.getJSON("/portal/visitor/getVisitorCount?rn="+Math.random(),function(js ...

  8. maven 国内镜像地址

    由于连接国外网站时网速特慢,为解决这个问题,os china 建立了一个maven 的私服.为了记忆,特将此记录. settings.xml 设置镜像方法步骤如下: 1. mirrors 设置 < ...

  9. List<T> 求差集

    List<, , , , , }; List<, , , , , }; List<int> c = b.Except(a).ToList(); foreach (int i i ...

  10. android--屏幕旋转方法总结

    在介绍之前,我们需要先了解默认情况下android屏幕旋转的机制: 默认情况下,当用户手机的重力感应器打开后,旋转屏幕方向,会导致当前activity发生onDestroy-> onCreate ...