树状数组+离散化

#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. Python 学习笔记4

    我是一个艺术家. 今天继续学习python啊.争取看到python流程控制.

  2. 将数组写入plist文件

    data 加载plist [NSBundle mainBundle] [arr writeToURL:<#(NSURL *)#> atomically:<#(BOOL)#>]

  3. php 创建文件

    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); $t ...

  4. 会话技术cookie和session详解

    什么是会话 会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. 会话技术解决了什么问题 每个用户与服务器进行交互的过程中,各自会有一 ...

  5. FTP、TFTP

      FTP 文件传送协议  (File Transfer Protocol) FTP是因特网上使用得最广泛的文件传送协议. 文件传送协议 FTP (File Transfer Protocol) 是因 ...

  6. bzoj1977

    1977: [BeiJing2010组队]次小生成树 Tree Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 3001  Solved: 751[Su ...

  7. mysql常用命令使用技巧

    一.连接Mysql格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root - ...

  8. JQuery中常用方法备忘

    本文转载自博客园,原文地址 http://www.cnblogs.com/xzf158/archive/2008/10/14/logan.html 1.Window.onload 的JQuery方法 ...

  9. jquery新窗口打开链接

    第一种:下面的代码是针对m35ui这个样式下的a都是在新窗口打开    <script type="text/javascript">  jQuery(document ...

  10. Ajax及select级联

    cascade.jsp(Test/WebContent/jsp/cascade.jsp): <%@ page language="java" contentType=&quo ...