PAT (Advanced Level) 1101. Quick Sort (25)
树状数组+离散化
#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)的更多相关文章
- 【PAT甲级】1101 Quick Sort (25 分)
题意: 输入一个正整数N(<=1e5),接着输入一行N个各不相同的正整数.输出可以作为快速排序枢纽点的个数并升序输出这些点的值. trick: 测试点2格式错误原因:当答案为0时,需要换行两次
- 1101. Quick Sort (25)
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- PAT甲题题解-1101. Quick Sort (25)-大水题
快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT (Advanced Level) 1109. Group Photo (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1105. Spiral Matrix (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...
- PAT (Advanced Level) 1071. Speech Patterns (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1063. Set Similarity (25)
读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT (Advanced Level) 1048. Find Coins (25)
先对序列排序,然后枚举较小值,二分较大值. #include<iostream> #include<cstring> #include<cmath> #includ ...
随机推荐
- Linux下搭建ntp时间同步服务器
1.ntpd软件安装(略过) 2.修改ntp.conf配置文件 vi /etc/ntp.conf 第一种配置:允许任何IP的客户机都可以进行时间同步将“restrict default kod nom ...
- hdu 5493 Queue treap实现将元素快速插入到第i个位置
input T 1<=T<=1000 n 1<=n<=100000 h1 k1 h2 k2 ... ... hn kn 1<=hi<=1e9 0<=ki&l ...
- 从Map、JSONObject取不存在键值对时的异常情况
1.在Map中取不存在的键值对时不会报异常,只会返回null. @Test public void testMap() { Map<String, Object> map = new Ha ...
- JSP之JavaBean
一.定义 1 JavaBean是一个遵循特定写法的Java类,它通常具有如下特点: 这个Java类必须具有一个无参的构造函数 属性必须私有化. 私有化的属性必须通过public类型的方法暴露给其它程序 ...
- Hbase查看
Client HBase Client使用HBase的RPC机制与HMaster和HRegionServer进行通信,对于管理类操作,Client与HMaster进行RPC:对于数据读写类操作,Cli ...
- android 属性动画
一直再追郭霖的博客和imooc上的一些新的视频,最近有讲到属性动画. 以下内容为博客学习以及imooc上视频资料的学习笔记: 在3.0之前比较常见的动画为tween动画和frame动画: tween动 ...
- spring Stack Overflow
1. ApplicationContext 不关闭,资源泄露问题: Spring ApplicationContext - Resource leak: 'context' is never clos ...
- chrome 常用快捷操作
Chrome窗口和标签页快捷键: Ctrl+N 打开新窗口 Ctrl+T 打开新标签页 Ctrl+Shift+N 在隐身模式下打开新窗口 Ctrl+O,然后选择文件,在谷歌浏览器中打开计算机上的文件 ...
- SpringSecurity自定义过滤器
applicationContext-security.xml: <beans:beans xmlns="http://www.springframework.org/schema/s ...
- SUPERVISOR进程管理器配置指南
SUPERVISOR进程管理器配置指南1. supervisor简介1.1. 官网http://supervisord.org/ 1.2. 介绍Supervisor是一个进程控制系统. 它是一个C/S ...