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,布布扣,bubuko.com
Round #169 (Div. 2)C. Little Girl and Maximum Sum
原文地址:http://www.cnblogs.com/hrhguanli/p/3777498.html