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. 三、编译第一步 make xxx_defconfig——Makefile.build 脚本

    3.1 上章分析回顾 3.1 上章分析出的参数 3.1.1 变量 MAKECMDGOALS = xxx_defconfig KBUILD_EXTMOD = version_h := include/g ...

  2. OptionParser命令参数介绍及使用

    使用optionParse解析命令行参数分以下几个步骤: 创建parser实例 使用add_option添加我们要处理的命令行参数 得到解析sys.argv后的options对象,查看用户的输入 代码 ...

  3. WF控制台工作流(2)

    using System; using System.Linq; using System.Activities; using System.Activities.Statements; namesp ...

  4. java线程池如何合理的设置大小

    线程池究竟设置多大要看你的线程池执行的什么任务了,CPU密集型.IO密集型.混合型,任务类型不同,设置的方式也不一样 任务一般分为:CPU密集型.IO密集型.混合型,对于不同类型的任务需要分配不同大小 ...

  5. SpringAOP+注解实现简单的日志管理

    今天在再次深入学习SpringAOP之后想着基于注解的AOP实现日志功能,在面试过程中我们也经常会被问到:假如项目已经上线,如何增加一套日志功能?我们会说使用AOP,AOP也符合开闭原则:对代码的修改 ...

  6. 为什么用pycharm在同目录下import,pycharm会报错,但是实际可以运行?

    问题已经找到了,pycharm不会将当前文件目录自动加入自己的sourse_path.右键make_directory as-->sources path将当前工作的文件夹加入source_pa ...

  7. Jetson tk1 安装OpenNI 1 +Xtion Pro +NiTE

    参考: http://blog.csdn.net/xiabodan/article/details/44496871 序: 由于第三方库 NiTE2.0 不支持 arm 架构的处理器,因此需要安装Op ...

  8. CROSSUI桌面工具 分布加载模块(Distributed UI Module) 与 主模块Module 之间数据传输!

    CROSSUI 基于 NW,如何在模Module 之间(主index.js and module1.js)传输数据?  http://www.crossui.com/Forum/post577.htm ...

  9. saltStack的event接口通过mysql数据库接收SaltStack批量管理日志

    event是一个本地的ZeroMQ PUB Interface,event是一个开放的系统,用于发送信息通知salt或其他的操作系统.每个event都有一个标签.事件标签允许快速制定过滤事件.除了标签 ...

  10. 解执行maven项目出现 SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”. error

    最近再弄maven项目,运行起来没有问题,但是Console控制台会报错,比如说如下的问题异常提示: 由此我们可以看出,报出错误的地方主要是slf4j的jar包,而故障码中“Failed to loa ...