2016暑假集训训练2 H题 Frosh Week

求逆序数的傻逼题。

用归并排序或者树状数组或者线段树

归并排序代码:

# include<stdio.h>
# define MAXN 500100

int a[MAXN],b[MAXN];
long long ans;

void merge(int l, int r)
{
	int k, p, q;
    if(l == r) return;
    int mid= (l+r)>>1;
    merge(l,mid);
    merge(mid+1,r);
    p = l; q = mid+1; k = l;
    while(p<=mid || q<=r) {
        if(p>mid || (q<=r && a[p]>a[q])) {
            b[k++]=a[q++];
            ans+=mid-p+1;
        }
        else
            b[k++]=a[p++];
    }
    for(k=l; k<=r; k++) a[k] = b[k];
    return ;

}

int main()
{
    int n;
    while(~scanf("%d",&n)) {
		ans = 0;
        for(int i=0;i<n;i++)
            scanf("%d",a+i);
        merge(0,n-1);
        printf("%I64d\n",ans);
    }
    return 0;
}

  

时间: 2024-10-20 06:44:53

2016暑假集训训练2 H题 Frosh Week的相关文章

2016暑假集训训练2 C题 食物链

带权并查集傻逼题 用拆点方法草过. 拆点代码: # include <stdio.h> # include <string.h> int set[150005], n, k, d; int find(int x) { int s, temp; for (s=x; set[s]>=0; s=set[s]) ; while (s != x) { temp = set[x]; set[x] = s; x = temp; } return s; } void union_set(in

2016暑假集训训练2 I题 Doing Homework again

傻逼贪心题. 先按照扣分从大到小排序,分数相同则按照截止日期从小到大排序.. 然后按顺序,从截止日期开始往前找没有占用掉的时间. 如果找不到了,则加到罚分里面. # include <stdio.h> # include <stdlib.h> # include <string.h> int h[1005][2], n, visit[1005]; int comp(const void * a, const void * b) { return *(((int*)b)+

2016暑假集训训练2 N题 Play on Words

水题不解释.... # include <stdio.h> # include <string.h> int dee[26], set[26], node[26], n; char s[1002]; int find(int x) { int s, temp; for (s=x; set[s]>=0; s=set[s]) ; while (s!=x) { temp = set[x]; set[x] = s; x = temp; } return s; } void union

POJ3156 暑假集训-最短路H题floyd http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82829#rank

  http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82829#rank#include<iostream> #include<algorithm> #include<string.h> #include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<limits.h> #include<mat

acm集训训练赛A题【签到题】

一.题目 Description After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of nhorizontal and m vertical sticks. An intersection point is any point on the grid which is formed by t

acm集训训练赛B题【排序+模拟】

一.原题 Description Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of ndistinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you

[暑假集训]区域赛套题集

2014-07-03 [浙江第11届省赛]ZOJ 3785 What day is that day?  (打表找循环节) [暑假集训]区域赛套题集

2016HUAS暑假集训训练题 F - 简单计算器

Description 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. Input 测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔.没有非法表达式.当一行中只有0时输入结束,相应的结果不要输出. Output 对每个测试用例输出1行,即该表达式的值,精确到小数点后2位. Sample Input 1 + 2 4 + 2 * 5 - 7 / 11 0 Sample Output 3.00 13.36 分析: 本题

2016HUAS暑假集训训练题 G - Oil Deposits

Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It