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. BFS && DFS

    HDOJ 1312 Red and Black http://acm.hdu.edu.cn/showproblem.php?pid=1312 很裸的dfs,在dfs里面写上ans++,能到几个点就调了 ...

  2. C#基础系列 - 抽象类及其方法的学习

    在C#中使用关键字 abstract 来定义抽象类和抽象方法. 不能初始化的类被叫做抽象类,它们只提供部分实现,但是另一个类可以继承它并且能创建它们的实例. "一个包含一个或多个纯虚函数的类 ...

  3. LANMPS 一键PHP环境安装包(转)

    转:http://www.lanmps.com/ LANMPS 一键安装包,php绿色环境套件包: https://github.com/foxiswho/lanmps 安装 Mar 17, 2017 ...

  4. O(n log log n)实现FGT和FLT(Fast GCD/LCM Transformation)

    本文是作者看不懂分治FFT之后开始娱乐一下自己写的 看到一道题时候询问了正解后,推出了一个奇怪的变换,发现这个很Transformation,我和正解推出来的奇怪的东西是一样的,但还是想写一下思路.. ...

  5. CentOS7.6安装rime輸入法

    # solve dependencyyum install -y gcc gcc-c++ boost boost-devel cmake make cmake3yum install glog glo ...

  6. Kafka/Metaq设计思想学习笔记

    http://my.oschina.net/geecoodeer/blog/194829

  7. vue 中 使用 tradingview

    加载页面时初始化方法: mounted 可以在 mounted 方法中调用 methods 的中的方法 使用 data 中的数据时,在每个方法的开始推荐先定义 var that = this 现在还不 ...

  8. 《Android源码设计模式》--Builder模式

    No1: 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示 No2: 在Android源码中,最常用到的Builder模式就是AlertDialog.Builder No3: ...

  9. Python之路【第九篇】:面向对象进阶

    阅读目录 一. isinstance(obj,cls)和issubclass(sub,super)二. 反射三. __setattr__,__delattr__,__getattr__四. 二次加工标 ...

  10. win10 远程桌面远程电脑时每次要输入密码及身份验证错误,要求的函数不受支持问题解决

    解决以前每次远程时能能记住密码,更新系统补丁后现在每次登录要输入密码了及远程时提示身份验证错误,要求的函数不受支持问题 解决方法一.卸载更新安装的新补丁,远程桌面正常,能记住密码 解决方法二.修改注册 ...