【题目分析】

  题目的意思是在一个数列中找到四个数,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的更多相关文章

  1. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  2. 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 ...

  3. 关于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交叉 ...

  4. c中使用gets() 提示warning: this program uses gets(), which is unsafe.

    今天在C代码中使用gets()时提示“warning: this program uses gets(), which is unsafe.”,然后这个程序还能运行,无聊的我开始查阅资料,为啥gets ...

  5. 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 ( ...

  6. 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 于是我在网 ...

  7. C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0

    C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0

  8. Program.cs

    Program.cs using System; namespace HelloWorld { class Program { [STAThread] static void Main(string[ ...

  9. 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配置文 ...

  10. 委托的例子,from C# advanced program

    class BubbleSorter { static public void Sort<T>(IList<T> sortArray, Func<T, T, bool&g ...

随机推荐

  1. android测试(转)

    1.冒烟测试 跟web端的测试流程一样,你拿到一个你们开发做出来的apk首先得去冒烟,也就是保证他的稳定性,指定时间内不会崩溃.这款原生sdk自带的monkey可以当做我们的测试工具.就跟我之前博客所 ...

  2. paper 24 :matlab的cat函数

    cat:用来联结数组 用法:C = cat(dim, A, B)       按dim来联结A和B两个数组. C = cat(dim, A1, A2, A3, ...)    按dim联结所有输入的数 ...

  3. 夺命雷公狗—angularjs—9—ng-class的自定义函数的用法

    angularjs里面其实给我们留下了一个很不错的地方,他就是可以直接调用函数从而对该位置进行处理, 被点击后展示效果如下所示: 开始走代码吧.... <!doctype html> &l ...

  4. SQL优化SQL tuning

    1. 索引不合适,走主键进行了key lookup查找   说明索引没有覆盖到where条件 或者  orderby 或者 group by的列

  5. yii2复选框

    Yii2复选框的具体使用方法如下,以商品中的品牌为例在页面显示 第一种方法:使用ActiveForm::checkBoxlist()(这种方法可以把后台获取到的数据都生成复选框),具体使用如下: &l ...

  6. Ceph的客户端丢失文件夹的解决办法

    原来的解决办法 更新linux内核,使用linux内核级的mount方式,一段时间后将会在客户端看不到部分长期不使用的文件夹 更正后的解决办法 参考Ceph的客户端安装设置ceph-fuse方式挂载c ...

  7. Android 带checkbox的listView 实现多选,全选,反选

    由于listview的一些特性,刚开始写这种需求的功能的时候都会碰到一些问题,重点就是存储每个checkbox的状态值,在这里分享出了完美解决方法:     布局文件: [html]   <?x ...

  8. Mongodb 笔记05 创建副本集

    创建副本集 1. 副本集:副本集时一组服务器,其中有一个主服务器(primary),用于处理客户端请求:还有多个备份服务器(secondary),用于保存主服务器的数据副本.如果主服务器崩溃了,备份服 ...

  9. Linux下后台程序完成自动输入密码等交互行为的例子

    今天要开发一个定时任务,然后加入cron列表中.但是有个问题摆在眼前,脚本的执行中需要输入数据库密码: mysql -u root -p << SQL use db; set names  ...

  10. Can't create/write to file '/tmp/#sql_887d_0.MYD' (Errcode: 17)

    lsof |grep "#sql_887d_0.MYD" 如果没有被占用就可以删掉 . https://wordpress.org/support/topic/cant-creat ...