Round #169 (Div. 2)C. Little Girl and Maximum Sum
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的更多相关文章
- Round #169 (Div. 2)D. Little Girl and Maximum XOR
1.首先是要找到一个位置从左至右,作l这一个是0,r这一个是1. 2.实例01011,10100.你将能够找到01111和10000. #include<cstdio> #include& ...
- Codeforces Round #169 (Div. 2)
A. Lunch Rush 模拟. B. Little Girl and Game 因为可以打乱顺序,所以只关心每种数字打奇偶性. 若一开始就是回文,即奇数字母为0或1种,则先手获胜. 若奇数字母大于 ...
- 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 ...
- 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 ...
- 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table
题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...
- 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 ...
- 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 ...
- BestCoder Round #11 (Div. 2) 前三题题解
题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...
- 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 ...
随机推荐
- 判断一个字符是否为数字的两种方法(C/C++)
在平时,我们经常遇见判断字符是否为数字这种题目,虽然感觉还是很简单,不过我是个更喜欢用函数的人,因为我觉得这样更便捷,所以我更推荐第二种方式. 1.直接判断 #include <stdio.h& ...
- Asp.net mvc 实时生成缩率图到硬盘
之前对于缩率图的处理是在图片上传到服务器之后,同步生成两张不同尺寸的缩率供前端调用,刚开始还能满足需求,慢慢的随着前端展示的多样化,缩率图已不能前端展示的需求,所以考虑做一个实时生成图片缩率图服务. ...
- Spark(十五)SparkCore的源码解读
一.启动脚本分析 独立部署模式下,主要由master和slaves组成,master可以利用zk实现高可用性,其driver,work,app等信息可以持久化到zk上:slaves由一台至多台主机构成 ...
- 四、oracle 用户管理 二
一.使用profile管理用户口令概述:profile是口令限制,资源限制的命令集合,当建立数据库时,oracle会自动建立名称为default的profile.当建立用户没有指定profile选项时 ...
- nginx中配置文件的讲解
一: 1.配置文件的结构 nginx由配置文件中指定的指令控制的模块组成. 指令分为简单指令和块指令. 一个简单的指令由空格分隔的名称和参数组成,并以分号(;)结尾. 块指令具有与简单指令相同的结构, ...
- chromedriver与chrome版本对应表,firefox、geckodriver
一. chromedriver与chrome对应表(记得就会更新): chromedriver版本 支持的Chrome版本 v2.36 v64-66 v2.35 v62-64 v2.34 v61-6 ...
- volatile 和锁的内存语义
一.volatile 的内存语义 1. volatile 的特性 volatile变量自身具有以下特性: 可见性 :对一个volatile变量的读,总是能看到(任意线程)对这个volatile变量最后 ...
- 查看锁信息(开启InnoDB监控)
当前mysql版本:5.6.21 一.背景 在mysql处理死锁问题时,由于show engine innodb status输出来的死锁日志无任务事务上下文,并不能很好地诊断相关事务所持有的所有锁信 ...
- Java 中类的初始化过程
先来一张 JVM 中的内存模型 . 在Java 虚拟机原理这本书中介绍了类会被初始化的 5 种情况 . 1 遇到 new getstatic putstatic 和 invokestatic 这 4 ...
- Hades:移动端静态分析框架
只有通过别人的眼睛,才能真正地了解自己 ——<云图> 背景 作为全球最大的互联网 + 生活服务平台,美团点评近年来在业务上取得了飞速的发展.为支持业务的快速发展,移动研发团队规模也逐渐从零 ...