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 ...
随机推荐
- Nginx正向代理让无法直接上网的机器通过代理上网
Nginx正向代理让无法直接上网的机器通过代理上网 在阿里云平台买了几台ECS.但是只要其中一台开通了公网.由于要初始化系统环境,需要网络安装相关依赖. Nginx正向代理配置: 一.Nginx 正向 ...
- BOOTICE(引导扇区维护工具) V1.3.3 中文免费绿色版
软件名称: BOOTICE(引导扇区维护工具)软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 357KB图片预览: 软件简 ...
- 一个初学者的辛酸路程-了解Python-2
前言 blog花了一上午写的,结果笔记本关机了,没有保存,找不到了,找不到了啊,所以说,你看的每一篇blog可能都是我写了2次以上的--.哎!! 代码改变世界,继续......... Python基础 ...
- treecnt
treecnt ﹡ LH (命题人) 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 给定一棵n个节点的树,从1到n标号.选择k个点,你需要选择一些边使得这k个点通过选择 ...
- 2.Thread中的实例方法
(转自:http://www.cnblogs.com/xrq730/p/4851233.html) Thread类中的方法调用方式: 1.this.XXX 这种调用方式表示的线程是:线程实例本身 2. ...
- php+ajax的三级联动下拉菜单
封装一个三级联动,就可以在任何页面进行引用了 先写个页面引用一下这个js <head> <meta http-equiv="Content-Type" conte ...
- android应用开发小技巧
1,实现应用可以安装到SD卡里面去:在AndroidManifest.xml文件的manifest里面添加下面一行: 1 android:installLocation="preferExt ...
- 类型“GridView”的控件必须放在具有 runat=server 的窗体标记内?
Response.AddHeader("content-disposition", "attachment;filename=CRM.xls") Respons ...
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation
当用GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误提示.有两种方法可以解决以上问题: 1.修改web ...
- Java多线程之~~~使用Exchanger在线程之间交换数据[这个结合多线程并行会有解决很多问题]生产者消费者模型
http://blog.csdn.net/a352193394/article/details/39503857 Java多线程之~~~使用Exchanger在线程之间交换数据[这个结合多线程并行会 ...