Contact ATC

我跑去列方程, 然后就gg了。。。

我们计每个飞机最早到达时间为L[ i ], 最晚到达时间为R[ i ],

对于面对面飞行的一对飞机, 只要他们的时间有交集则必定满足条件。

对于相同方向飞行的飞机, 只有其中一个的时间包含另一个的时间才满足条件。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); struct Bit {
int a[N];
void init() {
memset(a, , sizeof(a));
}
void modify(int x, int v) {
for(int i = x; i < N; i += i & -i)
a[i] += v;
}
int sum(int x) {
int ans = ;
for(int i = x; i; i -= i & -i)
ans += a[i];
return ans;
}
int query(int L, int R) {
if(L > R) return ;
return sum(R) - sum(L - );
}
}; struct Node {
Node(LL a, LL b) : a(a), b(b) {}
bool operator < (const Node& rhs) const {
return a * rhs.b < rhs.a * b;
}
bool operator == (const Node& rhs) const {
return a * rhs.b == rhs.a * b;
}
void print() {
printf("%.5f ", 1.0 * a / b);
}
LL a, b;
}; int n, w, x[N], v[N];
LL ans = ;
vector<PII> vc[];
vector<Node> hs;
Bit bit; bool cmp(PII& a, PII& b) {
if(a.fi == b.fi) return a.se < b.se;
return a.fi > b.fi;
} LL solve(vector<PII>& vc) {
bit.init();
LL ans = ;
sort(vc.begin(), vc.end(), cmp);
for(int i = ; i < SZ(vc); i++) {
ans += bit.sum(vc[i].se);
bit.modify(vc[i].se, );
}
return ans;
} int main() {
scanf("%d%d", &n, &w);
for(int i = ; i <= n; i++) {
scanf("%d%d", &x[i], &v[i]);
if(x[i] < ) {
hs.push_back(Node(-x[i], v[i] + w));
hs.push_back(Node(-x[i], v[i] - w));
} else {
hs.push_back(Node(x[i], w - v[i]));
hs.push_back(Node(x[i], -w - v[i]));
}
}
sort(hs.begin(), hs.end());
hs.erase(unique(hs.begin(), hs.end()), hs.end());
for(int i = ; i <= n; i++) {
if(x[i] < ) {
int L = lower_bound(hs.begin(), hs.end(), Node(-x[i], v[i] + w)) - hs.begin() + ;
int R = lower_bound(hs.begin(), hs.end(), Node(-x[i], v[i] - w)) - hs.begin() + ;
vc[].push_back(mk(L, R));
} else {
int L = lower_bound(hs.begin(), hs.end(), Node(x[i], w - v[i])) - hs.begin() + ;
int R = lower_bound(hs.begin(), hs.end(), Node(x[i], -w - v[i])) - hs.begin() + ;
vc[].push_back(mk(L, R));
}
}
ans += solve(vc[]);
ans += solve(vc[]);
ans += 1ll * SZ(vc[]) * SZ(vc[]);
bit.init();
for(auto& t : vc[]) bit.modify(t.se, );
for(auto& t : vc[]) ans -= bit.sum(t.fi - );
bit.init();
for(auto& t : vc[]) bit.modify(t.fi, );
for(auto& t : vc[]) ans -= bit.query(t.se + , N - );
printf("%lld\n", ans);
return ;
} /*
*/

Codeforces 924D Contact ATC (看题解)的更多相关文章

  1. Codeforces 269C Flawed Flow (看题解)

    我好菜啊啊啊.. 循环以下操作 1.从队列中取出一个顶点, 把哪些没有用过的边全部用当前方向. 2.看有没有点的入度和 == 出度和, 如果有将当前的点加入队列. 现在有一个问题就是, 有没有可能队列 ...

  2. Codeforces 436E Cardboard Box (看题解)

    Cardboard Box 贪了个半天贪不对, 我发现我根本就不会贪心. 我们先按b排序, 然后枚举选两颗心的b的最大值, 在这个之前的肯定都要选一个, 因为前面的要是一个都没选的话, 你可以把当前选 ...

  3. Codeforces 1045C Hyperspace Highways (看题解) 圆方树

    学了一下圆方树, 好神奇的东西呀. #include<bits/stdc++.h> #define LL long long #define fi first #define se sec ...

  4. Codeforces 1137D Cooperative Game (看题解)

    Cooperative Game 智商题, 感觉不太能推出来, 虽然看看证明过程是对的. #include<bits/stdc++.h> #define LL long long #def ...

  5. Codeforces 875F Royal Questions (看题解)

    我还以为是什么板子题呢... 我们把儿子当做点, 公主当做边, 然后就是求边权值最大基环树森林. #include<bits/stdc++.h> #define LL long long ...

  6. Codeforces 983C Elevator dp (看题解)

    Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...

  7. Codeforces 830C Bamboo Partition (看题解)

    Bamboo Partition 列公式, 整除分块, 想不到, 好菜啊. #include<bits/stdc++.h> #define LL long long #define fi ...

  8. Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)

    New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...

  9. Codeforces 1017F The Neutral Zone (看题解)

    这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...

随机推荐

  1. hud 2554 N对数的排列问题 (规律)

    题目链接 Problem Description 有N对双胞胎,他们的年龄分别是1,2,3,--,N岁,他们手拉手排成一队到野外去玩,要经过一根独木桥,为了安全起见,要求年龄大的和年龄小的排在一起,好 ...

  2. 2018-2019-2 网络对抗技术 20165320 Exp1 PC平台逆向破解

    学到的新知识总结 管道:符号为| 前一个进程的输出直接作为后一个进程的输入 输出重定向:符号为> 将内容定向输入到文件中 perl:一门解释性语言,不需要预编译,直接在命令行中使用.常与输出重定 ...

  3. SLAM学习资料汇总

    转自 http://www.cnblogs.com/wenhust/   书籍: 1.必读经典 Thrun S, Burgard W, Fox D. <Probabilistic robotic ...

  4. Linux定时任务调度

    ⒈概述 任务调度:是指系统在某个时间执行的特定的命令或程序 分类:1)系统任务:有些重要的工作必须周而复始的执行,例如病毒扫描等 2)用户任务:个别用户可能希望定时执行某些程序,例如mysql定时备份 ...

  5. Dubbo——基于Zookeeper服务框架搭建及案例演示

    一.了解SOA微服务架构 在大规模服务化之前,应用可能只是通过RMI或Hessian等工具,简单的暴露和引用远程服务,通过配置服务的URL地址进行调用,通过F5等硬件进行负载均衡. (1) 当服务越来 ...

  6. ES系列五、ES6.3常用api之搜索类api

    1.搜索api 1.1.routing:路由 执行搜索时,它将广播到所有索引/索引分片(副本之间的循环).可以通过提供routing参数来控制将搜索哪些分片.例如,在索引book时,路由值可以是nam ...

  7. mysql系列八、mysql数据库优化、慢查询优化、执行计划分析

    mysql的性能优化无法一蹴而就,必须一步一步慢慢来,从各个方面进行优化,最终性能就会有大的提升. 一.介绍 对mysql优化是一个综合性的技术,主要包括 表的设计合理化(符合3NF) 添加适当索引( ...

  8. Android Studio安装apk失败

    可能的情况 手机上已经安装了应用或者应用卸载不彻底 解决办法: adb uninstall yourpackagename 如果uninstall失败,可以考虑 clean一下Android Stud ...

  9. git 的入门使用到团队协作

    1.git 的安装.下载---安装,esay. 下载地址:https://git-for-windows.github.io/ 2.创建一个自己的身份 git config --global user ...

  10. 转载:为什么选择Nginx(1.2)《深入理解Nginx》(陶辉)

    原文:https://book.2cto.com/201304/19610.html 为什么选择Nginx?因为它具有以下特点: (1)更快 这表现在两个方面:一方面,在正常情况下,单次请求会得到更快 ...