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 ...
随机推荐
- 《精通Python设计模式》学习之工厂方法
小书,在我以前作数据库的连接时,就用了这个工厂方法的. 归纳总结一下,更有利于成长吧. import xml.etree.ElementTree as etree import json class ...
- Monaco Editor 使用入门
以前项目是用ace编辑器的,但是总有些不敬人意的地方.前端事件看见的VS Code编辑器Monaco Editor准备更换下,下面介绍一些使用中遇到的一点问题.代码提示 1.项目引用 import * ...
- sicily 1051. Biker's Trip Odomete
DescriptionMost bicycle speedometers work by using a Hall Effect sensor fastened to the front fork o ...
- 自定义Adapter为什么会重复多轮调用getView?——原来是ListView.onMeasure在作祟
相信很多人在使用自定义Adapter的时候都遇到这样的问题: 假设Adapter数据源中只有30个Item,理论上每显示一个新的Item的时候就会调用一次getView,均显示一次的话是要调用getV ...
- mysql关联表插入-php环境中
$insertsql=<<<EOTinsert into tb_manager values(null,'$name','$pwd','1');select @pid:=last_i ...
- pygame模块参数汇总(python游戏编程)
一.HelloWorld pygame.init() #初始函数,使用pygame的第一步: pygame.display.set_mod((600,500),0,32) #生成主屏幕screen:第 ...
- 使用MYSQL+Redis完成分页读取功能
public function getAnchorByPopularity($page, $pagesize){ //验证参数的正确性 if(!is_numeric($page) || !is_num ...
- 使用IDEA和Maven创建Javaweb项目
1.File -- New -- Project
- Spring技术内幕:设计理念和整体架构概述(转)
程序员都很崇拜技术大神,很大一部分是因为他们发现和解决问题的能力,特别是线上出现紧急问题时,总是能够快速定位和解决. 一方面,他们有深厚的技术基础,对应用的技术知其所以然,另一方面,在采坑的过程中不断 ...
- Java 中的定时任务(一)
定时任务简单来说就是在指定时间,指定的频率来执行一个方法,而在 Java 中我们又该如何实现呢? 想来主要有 3 种方式,最原始的方式肯定是开启一个线程,让它睡一会跑一次睡一会跑一次这也就达到了定频率 ...