【题目分析】

  题目的意思是在一个数列中找到四个数,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. [摘录]quarts:feature

    Features of Quartz Runtime Environments Quartz can run embedded within another free standing applica ...

  2. Web服务器处理HTTP压缩之gzip、deflate压缩

    现如今在处理http请求的时候,由于请求的资源较多,如果不启用压缩的话,那么页面请求的流量将会非常大.启用gzip压缩,在一定程度上会大大的提高页面性能.   目录 一.什么是gzip 二.什么是de ...

  3. 为VirtualBox里的Linux系统安装增强功能

    先说下为什么要安装增强功能, 很重要的原因是分辨率,没有安装增强功能的虚拟机里的系统往往不能全屏的,屏幕显示的内容没有充满整个屏幕. 还有主机和客户机之间共享文件夹也需要客户机的系统安装了增强功能. ...

  4. 【bs4】安装beautifulsoup

    Debian/Ubuntu,install $ apt-get install python-bs4 easy_install/pip $ easy_install beautifulsoup4 $ ...

  5. Server编解码 解决Response.Redirect方法传递汉字丢失或乱码

  6. Windows 10 访问网络共享 总是提示用户名或密码不正确的解决方法

    今天同事在Windows10上共享了一些文件,其他使用Windows 7的同事都可以正常使用,唯独我是使用Windows 10操作系统的,和别人输入一样的用户名和密码,却总是告诉我:用户名或密码不正确 ...

  7. Java笔试题解答和部分面试题

    面试类  银行类的问题 问题一:在多线程环境中使用HashMap会有什么问题?在什么情况下使用get()方法会产生无限循环? HashMap本身没有什么问题,有没有问题取决于你是如何使用它的.比如,你 ...

  8. Couchbase

    Couchbase介绍,更好的Cache系统 在移动互联网时代,我们面对的是更多的客户端,更低的请求延迟,这当然需要对数据做大量的 Cache 以提高读写速度. 术语 节点:指集群里的一台服务器. 现 ...

  9. inux设备驱动归纳总结(五):2.操作硬件——IO内存【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-80627.html inux设备驱动归纳总结(五):2.操作硬件——IO内存 xxxxxxxxxxxx ...

  10. HAL中通过JNI调用java方法【转】

    转载请注明本文出处:http://www.cnblogs.com/xl19862005 作者:Xandy 由于工作的需要,最近一直在研究HAL.JNI.Java方法之间互调的问题,并做了如下一些记录和 ...