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. git中的常用指令名及其意义

    add 添加新文件到 Git 代码仓库的索引中 $ git add filename mv 移动或重命名文件 $ git mv old-filename new-filename rm 从工作目录和 ...

  2. 如何修改Oracle用户密码

    大家如果不知道oracle数据库的密码的话,我们可以通过简单的命令行把密码进行修改. 1.打开cmd 2 在弹出的命令提示窗口输入 set oracle_sid=数据库名称(实例),回车.例如数据库名 ...

  3. java基础知识(一)

    基本特征:封装性,继承性,多态性 一些新特征: 静态导入:import static 包名 可变参数的函数:add(int -x) 增强版for循环: for(int x:xs) 自动拆箱: 基本类型 ...

  4. memcached学习——常用命令+基于java客户端的3种简单实现(二)

    常用命令: memcached设计的原则就是简单,所以支持的命令也不是特别多~ 1.查看memcached的状态,主要用于分析内存的使用状况.优化内存分配等 stats 查看memcached的运行状 ...

  5. MYSQL数据备份与还原学习笔记

    数据备份与还原   1.mysqldump 1.1 文件地址: E:\xampp\mysql\bin 文件名:mysqldump.exe CMD下进入mysqldump.exe cd E:\xampp ...

  6. C#_Test

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Plus ...

  7. Java 将自己定义的对象作为HashMap的key

    须要继承Map的equals函数和hashCode函数 package com.category; import java.util.HashMap; public class GenCategory ...

  8. Git使用之基于SSH的Gitserver的client配置(下篇)

    1.  软件安装 Git-1.9.2-preview20140411 TortoiseGit-1.8.8.0-64bit.msi 1.1 安装msysgit 很easy,基本就是一路下一步,有几个地方 ...

  9. [Angular 2]ng-class and Encapsulated Component Style2

    Many Components require different styles based on a set of conditions. Angular 2 helps you style you ...

  10. NYOJ 16 矩形嵌套(动态规划)

    矩形嵌套 时间限制: 3000 ms  |  内存限制: 65535 KB 难度: 4   描述 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅 ...