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. AC自动机修正

    #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #inc ...

  2. HDU_1238——最大子串搜索

    Problem Description You are given a number of case-sensitive strings of alphabetic characters, find ...

  3. HDU4436---str2int 后缀树组(12年天津区域赛)

    str2int Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  4. HDU5125--magic balls(LIS)

    题意:求a数组的LIS,但是加了一个条件,为了LIS最大 b[i] a[i]可以交换.最多交换mci: 赤果果的dp啊,可是这个题用线段树的话却会TLE,,由于查询的只是1-x的最大值 因此我们可以用 ...

  5. Java Hibernate 之 Session 状态

    Session接口是Hibernate向程序提供操纵数据库的最主要接口,是单线程对象,它提供了基本的保存.更新.删除和查询方法.它有一个缓存,保存了持久化对象,当清理缓存时,按照这些持久化对象同步更新 ...

  6. vb安装过程中 ntvdm.exe[9696]中发生未处理的win32异常

    最近电脑总是出问题导致我的学习效率很低,前几天在用VB6.0的时候有个知识点不太熟悉,于是按F1发现不会出来帮助文档.突然想到重新装系统之后忘记了安装MSDN帮助插件,就在我安装这个软件的时候发现电脑 ...

  7. spring 学习2

    package com.asm; //...省略导入的相关类 public class MessageController implements Controller { public ModelAn ...

  8. js中的函数,Date对象,Math对象和数组对象

    函数就是完成某个功能的一组语句,js中的函数由关键字 function + 函数名 + 一组参数定义;函数在定义后可以被重复调用,通常将常用的功能写成一个函数,利用函数可以使代码的组织结构更多清晰. ...

  9. 转义字符和ASCII

    一.字符(char)   数字(int)   屏幕显示 '\n'                      10                   换行 '\0'                   ...

  10. 【iOS基础】NSURLConnection

    一.大文件下载1.方案:利用NSURLConnection和它的代理方法1> 发送一个请求 // 1.URL NSURL *url = [NSURL URLWithString:@"h ...