传送门 题意 给出n个数,m次访问,每次询问[L,R]的数有多少种排列 分析 \(n,m<=30000\),我们采用莫队算法,关键在于区间如何\(O(1)\)转移,由排列组合知识得到,如果加入一个数,\(区间值*区间长度/该数出现次数\),减去一个数则相反操作讲解 trick 1.我的原先莫队写法不能ac,原因是我传入的L,R是全局变量,在insert和erase前就++,--了,而没有达到预期目的,把R++,L--分离即可 代码 //wa #include <bits/stdc++.h>…
NPY and girls Problem Description NPY's girlfriend blew him out!His honey doesn't love him any more!However, he has so many girlfriend candidates.Because there are too many girls and for the convenience of management, NPY numbered the girls from 1 to…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5145 [题目大意] 给出一个数列,每次求一个区间数字的非重排列数量.答案对1e9+7取模. [题解] 我们发现每次往里加入一个新的数字或者减去一个新的数字,前后的排列数目是可以通过乘除转移的,所以自然想到用莫队算法处理.因为答案要求取模,所以在用除法的时候要计算逆元. [代码] #include <cstdio> #include <algorithm> #include <…
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description NPY's girlfriend blew him out!His honey doesn't love him any more!However, he has so many girlfriend candidates.Because there are too many girls and…
题意: cases T(1≤T≤10) (0<n,m≤30000) (0<ai≤30000)    n个数ai 表示n个女孩所在教室 m次询问 [L,R](1 <= L <= R <= n)     问访问所有女孩的顺序方案数(进教室顺序)为多少(一次进教室只能访问一个人)    分析: 莫队算法 + 排列数 一个区间内的方案数为 C(m,c1)*C(m-c1,c2)*C(m-c1-c2,c3)*....*C(cn,cn)    每次转移通过下式: C(m+1,n+1) =…
题目地址:HDU 5145 莫队真的好奇妙.. 这种复杂度竟然仅仅有n*sqrt(n)... 裸的莫队分块,先离线.然后按左端点分块,按块数作为第一关键字排序.然后按r值作为第二关键字进行排序. 都是从小到大,能够证明这种复杂度仅仅有n*sqrt(n). 然后进行块之间的转移. 代码例如以下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5145 题意:给你n,m,共有n个女孩,标号为1—n,n个数xi表示第ith个女孩在第xi个教室,然后下面有m个询问,每个询问有l,r两个数,表示要去找编号为l到r的女孩,每进一次教室只能找一个女孩,问有多少种组合方式,不同的组合方式定义为去教室的顺序不同. 题解:这题是离线的,很容易想到用莫队分块做,主要是要找出状态转移的方程,对于询问区间[l,r],假设这个区间的女孩一共分布在k个教室,每个教室有…
NPY and girls Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 790    Accepted Submission(s): 280 Problem Description NPY's girlfriend blew him out!His honey doesn't love him any more!However, he…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6278 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Problem Description The h-index of an author is the largest h where he has at least h papers with citations not les…
Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others)Total Submission(s): 2808    Accepted Submission(s): 826 Problem Description In this problem we consider a rooted tree with N vertices. The vertices ar…