博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cf1043E. Mysterious Crime(二分 前缀和)
阅读量:4573 次
发布时间:2019-06-08

本文共 2269 字,大约阅读时间需要 7 分钟。

题意

Sol

考场上做完前四题的时候大概还剩半个小时吧,那时候已经困的不行了。

看了看E发现好像很可做??

又仔细看了几眼发现这不是sb题么。。。

先考虑两个人,假设贡献分别为\((x, y) (a, b)\)

有两种组合方式,一种是\(x + b\),另一种是\(y + a\)

\(x + b >= y + a\)

那么\(x - y >= a - b\)

因此我们按照\(x - y\)排序,对于每个位置,肯定是某一个前缀全选\(x+b\),除此之外都是\(y+a\)

二分之后前缀和后缀和安排一下

#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
//#include
#define Pair pair
#define MP(x, y) make_pair(x, y)#define fi first#define se second#define int long long#define LL long long#define ull unsigned long long#define rg register#define pt(x) printf("%d ", x);//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)//char buf[(1 << 22)], *p1 = buf, *p2 = buf;//char obuf[1<<24], *O = obuf;//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}//#define OS *O++ = ' ';using namespace std;//using namespace __gnu_pbds;const int MAXN = 6e5 + 10, INF = 1e9 + 10, mod = 998244353;const int base = 137;const double eps = 1e-9;inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f;}int N, M, x[MAXN], y[MAXN], cha[MAXN];struct Node { int x, y, val; bool operator < (const Node &rhs) const { return val < rhs.val; }}a[MAXN];int sx[MAXN], sy[MAXN], ans[MAXN];int calc(int x, int y, int a, int b) { return min(x + b, y + a);} main() { N = read(); M = read(); for(int i = 1; i <= N; i++) { x[i] = a[i].x = read(), y[i] = a[i].y = read(); cha[i] = a[i].val = a[i].x - a[i].y; } for(int i = 1; i <= M; i++) { int p = read(), q = read(); int mn = calc(a[p].x, a[p].y, a[q].x, a[q].y); ans[p] -= mn; ans[q] -= mn; } sort(a + 1, a + N + 1); sort(cha + 1, cha + N + 1); for(int i = 1; i <= N; i++) sx[i] = sx[i - 1] + a[i].x; for(int i = N; i >= 1; i--) sy[i] = sy[i + 1] + a[i].y; for(int i = 1; i <= N; i++) { int pos = upper_bound(cha + 1, cha + N + 1, x[i] - y[i]) - cha - 1; ans[i] += y[i] * pos + sx[pos] + (N - pos) * x[i] + sy[pos + 1] - calc(x[i], y[i], x[i], y[i]); } for(int i = 1; i <= N; i++) cout << ans[i] << " "; return 0;}

转载于:https://www.cnblogs.com/zwfymqz/p/9874646.html

你可能感兴趣的文章
2019最新版Devops工具集
查看>>
解决/dev/fb0无法打开的问题
查看>>
U-Boot Reference Manual
查看>>
Scrapy 基础-01
查看>>
单链表反转
查看>>
[Hibernate] - EAGER and LAZY
查看>>
数据结构和算法系列12 五大查找之二叉排序树
查看>>
linux uname 命令详解
查看>>
金融量化分析【day113】:羊驼策略
查看>>
keep-alive
查看>>
bzoj 1076 状态压缩最优期望
查看>>
SpringMVC
查看>>
iOS 列表界面如何优雅实现模块化与动态化
查看>>
动态更改数据属性
查看>>
基于Flask开发企业级REST API应用(二)
查看>>
Linux系统下建svn服务器
查看>>
机器学习——梯度下降算法
查看>>
ubuntu18.04安装Charles及问题
查看>>
python+opencv+pil实现windows 图片位置查找
查看>>
ubuntu18.04安装postman
查看>>