[P2657]低头一族
来源:互联网 发布:剑灵召唤师女捏脸数据 编辑:程序博客网 时间:2024/06/10 09:36
原题链接
树状数组
这个题的题解到处都是啦
安利一下同学的讲解某不愿意透露姓名的绅士
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<cmath>#include<queue>#include<vector>#include<climits>#include<string>#include<cstdlib>#include<ctime>#define LL long long#define MOD 1000000007#define pi 3.141592653589using namespace std;struct nico{ LL v,x;}cow[200005];LL n,maxn,s,sp,cnt,ans,sum[200005],tot[200005];void add(int p,int w){ for(LL i=p;i<=maxn;i+=(i&-i)) { sum[i]++; tot[i]+=w; }}void ask(int p){ for(LL i=p;i>0;i-=(i&-i)) { cnt+=sum[i]; sp+=tot[i]; }}bool comp(nico a,nico b){ return a.v<b.v;}int main(){ LL i; scanf("%lld",&n); for(i=1;i<=n;i++) { scanf("%lld%lld",&cow[i].v,&cow[i].x); maxn=max(cow[i].x,maxn); } sort(cow+1,cow+n+1,comp); for(i=1;i<=n;i++) { s+=cow[i].x; sp=0; cnt=0; add(cow[i].x,cow[i].x); ask(cow[i].x); ans+=(cnt*cow[i].x-sp)*cow[i].v; cnt=i-cnt; sp=s-sp; ans+=(sp-cnt*cow[i].x)*cow[i].v; } printf("%lld",ans); return 0;}
阅读全文
1 0
- [P2657]低头一族
- P2345 奶牛集会/P2657 低头一族
- 洛谷2657 低头一族
- 某考试题~低头一族 [好题](简要的数学推倒)[四星]
- 记住低头
- 学会低头
- 该低头时就低头
- 低笑点一族
- 上班一族
- 程序员一族
- 时尚一族
- 上班一族
- LSH一族
- 该低头时就低头(8.27)
- 不向复杂低头
- 低头也是一种智慧
- 我在低头沉思...
- 抬头,低头,平视
- python进行机器学习中的SVM
- java Class与静态初始化
- jemalloc横向分析(六)tcache_event事件执行
- CodeForces
- 设计模式之单例模式
- [P2657]低头一族
- Centos7.0 安装ELK(5.5.1版本)
- 老用户快速从经典网络迁移VPC,阿里云提供便捷解决方案
- Party Games UVA
- 学习RxJava
- 监听div内容的变化
- 指针与数组的示例代码(帮助理解)
- Sublime和Notepad++小技巧
- Log日志打印工具类