求逆序的个数。首先处理出对n个数它所有排列的逆序的个数。然后,按位枚举,当枚举的数少于当前位,逆序数的个数就是前面确定的数对于后面数的逆序总数+后面k个数的排列的逆序总数。

1Y。

#include<cstdio>
#include<cmath>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 100005;
long long a[maxn], b[maxn], X1, X2, Y1, Y2, P, ans;
int n; long long inv(long long x, long long m)
{
if (x == 1) return x;
return inv(m % x, m)*(m - m / x) % m;
} long long C(int x, int y)
{
if (x > y) return 0;
return (a[y] * b[x]) % P * b[y - x] % P;
} long long c(int x, int y)
{
if (x > y) return 0;
if (y >= P) return C(x % P, y % P)*c(x / P, y / P) % P;
else return C(x, y);
} int main()
{
while (cin >> X1 >> Y1 >> X2 >> Y2 >> P)
{
a[0] = b[0] = 1;
for (int i = 1; i <= min(X2 + 1, P - 1); i++)
{
a[i] = (a[i - 1] * i) % P;
b[i] = inv(a[i], P);
}
ans = 0;
for (int i = Y1; i <= Y2; i++)
{
(ans += c(i + 1, X2 + 1) - c(i + 1, X1)) %= P;
}
(ans += P) %= P;
cout << ans << endl;
}
return 0;
}

  

HDU 5225的更多相关文章

  1. hdu 5225 Tom and permutation(回溯)

    题目链接:hdu 5225 Tom and permutation #include <cstdio> #include <cstring> #include <algo ...

  2. HDU 5225 枚举

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5225 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  3. BestCoder Round #40

    T1:Tom and pape (hdu 5224) 题目大意: 给出一个矩形面积N,求周长的最小值.(长&&宽&&面积都是正整数) N<=109 题解: 没啥好 ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. ACM_Alien And Password

    Alien And Password Time Limit: 2000/1000ms (Java/Others) Problem Description: Alien Fred wants to de ...

  2. 316 Remove Duplicate Letters 去除重复字母

    给定一个仅包含小写字母的字符串,去除重复的字母使得所有字母出现且仅出现一次.你必须保证返回结果是所有可能结果中的以字典排序的最短结果.例如:给定 "bcabc"返回 "a ...

  3. [转]mysql触发器的作用及语法

    转自:http://blog.csdn.net/cloudday/article/details/6905590 触发器是一种特殊的存储过程,它在插入,删除或修改特定表中的数据时触发执行,它比数据库本 ...

  4. 学习Objective-C入门教程(分享)

    原百度文库连接:http://wenku.baidu.com/view/6786064fe518964bcf847c63.html PS:需要原文档的可以留邮箱发送! (我叫雷锋,不要谢我) 学习Ob ...

  5. photoshop制作古风画

    效果图: 素材结构: 前期准备: 素材准备,我的素材包括:印章.花束.二次元妹纸,背景图片. 软件准备,用的软件是 photoshop CS6. 把二次元妹纸拖入photoshop,把她抠出来,Ctr ...

  6. 安卓socket 心跳和信鸽自定义提示音

    /** * 连接socket 和心跳 */ public class SocketService extends Service { private static addNewOrderInterfa ...

  7. webSocket客服在线交谈

    一>用户端 <%@ page language="java" pageEncoding="UTF-8" %><%@ taglib uri ...

  8. 探索java世界中的日志奥秘

                    java日志简单介绍 对于一个应用程序来说日志记录是必不可少的一部分.线上问题追踪,基于日志的业务逻辑统计分析等都离不日志.JAVA领域存在多种日志框架,目前常用的日志 ...

  9. JS——input标签注册事件

    注意:淘宝的lable是用定位制作的,事件是oninput事件 <!DOCTYPE html> <html> <head lang="en"> ...

  10. Json——转义符

    C#后台直接输出Json字符串需要反斜杠“\” context.Response.Write("[{\"Name\": \"wqx\", \" ...