http://codeforces.com/contest/362/problem/C

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int a[];
int c[];
int n; int lowbit(int x)
{
return x&(-x);
} void add(int x)
{
while(x>)
{
c[x]++;
x-=lowbit(x);
}
} int sum(int x)
{
int sum1=;
while(x<=n)
{
sum1+=c[x];
x+=lowbit(x);
}
return sum1;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
a[i]++;
}
int t1=,temp,t2=;
int max1=-;
for(int i=; i<n; i++)
{
memset(c,,sizeof(c));
for(int j=i+; j<=n; j++)
{
if(a[i]>a[j])
{
t1++;
temp=+*sum(a[j]);
if(temp>max1) {max1=temp; t2=;}
if(temp==max1) t2++;
add(a[j]);
}
}
}
printf("%d %d\n",t1-max1,t2);
}
return ;
}

cf C. Insertion Sort的更多相关文章

  1. [LeetCode] Insertion Sort List 链表插入排序

    Sort a linked list using insertion sort. 链表的插入排序实现原理很简单,就是一个元素一个元素的从原链表中取出来,然后按顺序插入到新链表中,时间复杂度为O(n2) ...

  2. 经典排序算法 – 插入排序Insertion sort

    经典排序算法 – 插入排序Insertion sort  插入排序就是每一步都将一个待排数据按其大小插入到已经排序的数据中的适当位置,直到全部插入完毕. 插入排序方法分直接插入排序和折半插入排序两种, ...

  3. leetcode Insertion Sort List

    题目:Sort a linked list using insertion sort. 代码: /** * Definition for singly-linked list. * struct Li ...

  4. 【leetcode】Insertion Sort List (middle)

    Sort a linked list using insertion sort. 思路: 用插入排序对链表排序.插入排序是指每次在一个排好序的链表中插入一个新的值. 注意:把排好序的部分和未排序的部分 ...

  5. 9. Sort List && Insertion Sort List (链表排序总结)

    Sort List Sort a linked list in O(n log n) time using constant space complexity.                   H ...

  6. LeetCode OJ 147. Insertion Sort List

    Sort a linked list using insertion sort. Subscribe to see which companies asked this question 解答 对于链 ...

  7. Java for LeetCode 147 Insertion Sort List

    Sort a linked list using insertion sort. 解题思路: 插入排序,JAVA实现如下: public ListNode insertionSortList(List ...

  8. 【LeetCode OJ】Insertion Sort List

    Problem: Sort a linked list using insertion sort. The node of the linked list is defined as: /** * D ...

  9. 147. Insertion Sort List

    Sort a linked list using insertion sort. 代码如下: /** * Definition for singly-linked list. * public cla ...

随机推荐

  1. linux内存管理子系统

    一.Linux内存管理模型 1.虚拟地址与物理地址的映射 2.物理地址的分配二.虚拟地址与物理地址的映射 1.虚拟地址空间分布 32位处理器有32根地址总线,可访问4G的物理空间.其中有0-3G为用户 ...

  2. C++中输出流运算符的重载

    cout是ostream类的对象,cin是istream类的对象. 我们平时用的cout<<就相当于cout.operator<<(...).也就是说正常使用(不对operat ...

  3. 创建多模块maven项目

    有两种方式: 1,new -->maven project-->maven-archetype-quickstart 建完多个独立的project后,手动修改pom文件的packing类型 ...

  4. layPage异步分页

    layPage分页,参照官网实例写了一份.如下: function InitDataByPage(curr) { ; $.getJSON("InitDataByPage", { & ...

  5. spring xml记录

    web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2 ...

  6. 对list集合去重操作

    import java.util.ArrayList; import java.util.List; //删除集合中重复的数据 public class RemoteTheSameDataInList ...

  7. StringBuffer和StringBuilder使用方法比較

    StringBuffer是字符串缓冲区,是一个容器. 特点: 1,长度是可变化的. 2,能够字节操作多个数据类型. 3,终于会通过toString方法变成字符串. C create U update ...

  8. linux服务器内存占用太高-释放内存

    修改/proc/sys/vm/drop_caches,释放Slab占用的cache内存空间(参考drop_caches的官方文档): Writing to this will cause the ke ...

  9. ls 命令详解

    1.ls基本语法及选项 用法:ls [选项]... [文件]... List information about the FILEs (the current directory by default ...

  10. [编译原理代码][NFA转DFA并最小化DFA并使用DFA进行词法分析]

    #include <iostream> #include <vector> #include <cstring> #include "stack" ...