program


【题目分析】
题目的意思是在一个数列中找到四个数,a[i]=a[j]<a[k]=a[l],其他都扯淡。
先把这些数sort一下,所有相等的数字就都排在一起了,然后这个数列可以按照数字的种类划分成一些段,每一段的数字都是相同的(1 1 4 4 5 5 6 12 12 12) ,每一个段和他后面的段都可以组成满足题目条件的答案。而每个段中的选择方式又有len^2种,我们维护一个前缀和数组sum[i]记录从第一段到第i段的每段组合数的和
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int mo=1e9+;
const int maxn=1e6+;
int n;
int a[maxn],num[maxn],sum[maxn];
int ans;
int x;
int main()
{
// freopen("program.in","r",stdin);
// freopen("program.out","w",stdout);
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
for(int i=;i<=n;i++)
num[i]=;
for(int i=;i<=n;i++)
{
if(a[i]!=a[i-])
x++;
num[x]++;
}
for(int i=;i<=x;i++)
num[i]=(num[i]*num[i])%mo;
for(int i=;i<=x;i++)
sum[i]=sum[i-]+num[i];
for(int i=;i<x;i++)
ans=(ans+num[i]*(sum[x]-sum[i]))%mo;
cout<<ans;
fclose(stdin);fclose(stdout);
return ;
}
program的更多相关文章
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- Solved: “Cannot execute a program. The command being executed was \roslyn\csc.exe”
When you publish your ASP.NET project to a hosting account such as GoDaddy, you may run into the iss ...
- 关于The C compiler "arm-none-eabi-gcc" is not able to compile a simple test program. 的错误自省...
在 GCC ARM Embedded https://launchpad.net/gcc-arm-embedded/ 上面下载了个arm-none-eabi-gcc 用cmake 编译时 #指定C交叉 ...
- c中使用gets() 提示warning: this program uses gets(), which is unsafe.
今天在C代码中使用gets()时提示“warning: this program uses gets(), which is unsafe.”,然后这个程序还能运行,无聊的我开始查阅资料,为啥gets ...
- Unable to load R3 module D:\Program Files\Oracle\VirtualBox/VBoxDD.DLL (VBoxDD): GetLastError=1790 (VERR_UNRESOLVED_ERROR).
Unable to load R3 module D:\Program Files\Oracle\VirtualBox/VBoxDD.DLL (VBoxDD): GetLastError=1790 ( ...
- Git for Windows - The Program can't start because libiconv2.dll is missing
今天在新装的win10 预览版上面,发现git不能启动了,提示信息主要是: The Program can't start because libiconv2.dll is missing 于是我在网 ...
- C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0
C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0
- Program.cs
Program.cs using System; namespace HelloWorld { class Program { [STAThread] static void Main(string[ ...
- sudo: no tty present and no askpass program specified(转)
sudo: no tty present and no askpass program specified 2012-11-30 09:30 5040人阅读 评论(1) 收藏 举报 修改sudo配置文 ...
- 委托的例子,from C# advanced program
class BubbleSorter { static public void Sort<T>(IList<T> sortArray, Func<T, T, bool&g ...
随机推荐
- [转]Chrome 控制台console的用法
Chrome 控制台console的用法 下面我们来看看console里面具体提供了哪些方法可以供我们平时调试时使用. 目前控制台方法和属性有: ["$$", "$x&q ...
- 阿里 drds 分布式数据库分节点查询
mybatis 模式下,xml 中写法 <select id="selectFailDetailOneNode" resultMap="BaseResultMap& ...
- 夺命雷公狗jquery---6属性选择器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 表单和验证事件以及marquee标签
1.表单验证<form></form> (1).非空验证(去空格) (2).对比验证(跟一个值对比) (3).范围验证(根据一个范围进行判断) (4).固定格式验证:电话号码, ...
- yii2 render和renderPartial区别
1.render()方法使用到项目中的布局layout,renderPartial()不使用布局
- Server编解码 解决Response.Redirect方法传递汉字丢失或乱码
- 《C语言入门很简单》欢乐槽点
p24 在C语言中,有三种基本的数据类型供选择,它们有着不同的精度和广度,可以根据自己的需要选择合适的.这三种数据类型分别是整型.浮点型.字符型,它们可谓是C语言数据的三大变形金刚. p237 评:自 ...
- 财务比率:ROE, 净利润增长率、毛利率、市盈率、PEG
净资产收益率是判断资产回报率指标,是最重要的财务数据 净利润增长率企业成长的参考指标 净利率企业获利能力的指标 毛利率企业获利能力的指标 资产负债率企业偿还债务的能力,也是重要的风险指标之其他还要根据 ...
- :not(selector)
描述: 用于筛选的选择器 查找所有未选中的 input 元素 HTML 代码: <input name="apple" /> <input name=" ...
- E2PROM与Flash的引脚图
E2PROM(24C02):