1、用退化的线段树(也就是没有区间查询)做。。。

2、注意longlong。

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

int n,q;

int a[200010],s[200010];

int main(){

    scanf("%d%d",&n,&q);

for(int i=1;i<=n;i++)

scanf("%d",&a[i]);

sort(a+1,a+1+n);

memset(s,0,sizeof(s));

    for(int j=1;j<=q;j++){

int l,r;

scanf("%d%d",&l,&r);

s[l]++;

s[r+1]--;

}

for(int i=1;i<n;i++)

s[i+1]+=s[i];

sort(s+1,s+1+n);

long long ans=0;

for(int i=1;i<=n;i++)

ans+=(long long)a[i]*s[i];

cout<<ans<<endl;

return 0;

}

Round #169 (Div. 2)C. Little Girl and Maximum Sum的更多相关文章

  1. Round #169 (Div. 2)D. Little Girl and Maximum XOR

    1.首先是要找到一个位置从左至右,作l这一个是0,r这一个是1. 2.实例01011,10100.你将能够找到01111和10000. #include<cstdio> #include& ...

  2. Codeforces Round #169 (Div. 2)

    A. Lunch Rush 模拟. B. Little Girl and Game 因为可以打乱顺序,所以只关心每种数字打奇偶性. 若一开始就是回文,即奇数字母为0或1种,则先手获胜. 若奇数字母大于 ...

  3. Codeforces Round #169 (Div. 2) E. Little Girl and Problem on Trees dfs序+线段树

    E. Little Girl and Problem on Trees time limit per test 2 seconds memory limit per test 256 megabyte ...

  4. Codeforces Round #169 (Div. 2) A水 B C区间更新 D 思路

    A. Lunch Rush time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table

    题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...

  6. codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j ...

  7. Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table【递推】

    A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. drools7 (三、kmodule 介绍)

    注意几点: 1. kmodule 有默认的加载路径, 看  KieModuleModelImpl 这个类的源代码 public class KieModuleModelImpl implements ...

  2. Java开发工程师学习路线

    贴一个比较出名的Java开发工程师学习路线图 好好学习提升中 这个貌似也不是特别全,算法,设计模式,架构好像都没有

  3. 【51nod】1251 Fox序列的数量

    题解 容斥题 我们枚举出现次数最多的数出现了K次 然后我们需要计算的序列是所有数字出现个数都不超过K - 1次 我们枚举不合法的数字的数目j,说明这个排列里除了我们固定出现K次的数至少有j个数是不合法 ...

  4. Haproxy 开启日志记录

    CentOS 7上yum安装的Haproxy,默认没有记录日志.需要做一下配置才能记录日志.(不知道其他版本是否需要,已经忘记了)主要是用到了Haproxy,以前貌似没有这么麻烦,今天配置出了一些问题 ...

  5. Xiaoguang Tu's Home Page

    Xiaoguang Tu (涂晓光): CV: Ph.D. Candidate of School of Communication and Information Engineering, Univ ...

  6. 内核启动文件系统后第一个执行的文件(inittab启动脚本分析)

    Linux 开机脚本启动顺序: 第一步:启动内核 第二步:执行init (配置文件/etc/inittab) 第三步:启动相应的脚本,执行inittab脚本,并且执行里面的脚本/etc/init.d ...

  7. iOS 11开发教程(五)iOS11模拟器介绍二

    iOS 11开发教程(五)iOS11模拟器介绍二 3.iOS11模拟器中设置语言 对于不同国家的人来说,使用到的语言是不一样的.一般情况下iOS11模拟器默认使用的English(英语).对于英文不好 ...

  8. MongoDB基本方法

    一.MongoDB Limit与Skip方法 MongoDB Limit() 方法 如果你需要在MongoDB中读取指定数量的数据记录,可以使用MongoDB的Limit方法,limit()方法接受一 ...

  9. Questions(Updating)

    有时候做题时会遇到一些未学习的零碎知识点,或存疑的疑惑 为防止遗忘,在此记录 1.复数除法与线性变换的关系 Accepted Codeforces 8D(2018.5.9) Definition: 复 ...

  10. 【转载】利用一个堆溢出漏洞实现 VMware 虚拟机逃逸

    1. 介绍 2017年3月,长亭安全研究实验室(Chaitin Security Research Lab)参加了 Pwn2Own 黑客大赛,我作为团队的一员,一直专注于 VMware Worksta ...