Codeforces 924D 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 (看题解)的更多相关文章
- Codeforces 269C Flawed Flow (看题解)
我好菜啊啊啊.. 循环以下操作 1.从队列中取出一个顶点, 把哪些没有用过的边全部用当前方向. 2.看有没有点的入度和 == 出度和, 如果有将当前的点加入队列. 现在有一个问题就是, 有没有可能队列 ...
- Codeforces 436E Cardboard Box (看题解)
Cardboard Box 贪了个半天贪不对, 我发现我根本就不会贪心. 我们先按b排序, 然后枚举选两颗心的b的最大值, 在这个之前的肯定都要选一个, 因为前面的要是一个都没选的话, 你可以把当前选 ...
- Codeforces 1045C Hyperspace Highways (看题解) 圆方树
学了一下圆方树, 好神奇的东西呀. #include<bits/stdc++.h> #define LL long long #define fi first #define se sec ...
- Codeforces 1137D Cooperative Game (看题解)
Cooperative Game 智商题, 感觉不太能推出来, 虽然看看证明过程是对的. #include<bits/stdc++.h> #define LL long long #def ...
- Codeforces 875F Royal Questions (看题解)
我还以为是什么板子题呢... 我们把儿子当做点, 公主当做边, 然后就是求边权值最大基环树森林. #include<bits/stdc++.h> #define LL long long ...
- Codeforces 983C Elevator dp (看题解)
Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...
- Codeforces 830C Bamboo Partition (看题解)
Bamboo Partition 列公式, 整除分块, 想不到, 好菜啊. #include<bits/stdc++.h> #define LL long long #define fi ...
- Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...
- Codeforces 1017F The Neutral Zone (看题解)
这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...
随机推荐
- Composer 安装和使用
1.linux下安装 curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer ...
- jaxp实现对xml文档的增,删,改,查操作(附源码)浅析
jaxp,属于javase中的一部分.是对xml进行解析的一个工具类: 既然说到这里,还是讲全一点,讲讲上面说到的xml的解析技术. xml的一个标记型文档. 在html的层级结构中,它会在内存中分配 ...
- Python 升级致yum 问题,pip 异常
升级 Python 导致 yum 和 pip 异常: 一些storm 和 自定义项目 需要升级python版本:Linux 系统默认是2.6 版本 ,所以需要根据业务进行升级操作:Python 官方下 ...
- js 判断身份证好是否合法
function cidInfo(sId){ var info="" //if(!/^\d{17}(\d|x)$/i.test(sId))return false; sId=sId ...
- android AysncTask使用
1.继承AysncTask类 例子: class downloadTask extends AsyncTask<Void,Integer,Boolean> 第一个参数是传入的参数 第二个参 ...
- css 背景图片自适应元素大小
一.一种比较土的方法,<img>置于底层. 方法如下: CSS代码: HTML: <img src="背景图片路径" /> <span>字在背景 ...
- 如何将SVN仓库转换为Git仓库
按如下步骤操作就可以将SVN仓库完整的转换为Git仓库: 1) 将远程SVN仓库搬到本地(这一步主要是为了提高转换的速度,也可以忽略) 参考这篇文章: http://rongjih.blog. ...
- NandFlash和iNand
nand 1.nand的单元组织:block与page(大页Nand与小页Nand)(1)Nand的页和以前讲过的块设备(尤其是硬盘)的扇区是类似的.扇区最早在磁盘中是512字节,后来也有些高级硬盘扇 ...
- HTMl学习笔记02-编辑器
工欲善其事,必先利其器 使用专业HTML编辑器来编辑HTML,推荐使用Notepad++,中文界面. 在Notepad++安装完成后,点击文件>新建.语言>H中选择HTML 在新建的文件输 ...
- python2.7源码或第三方包里埋藏的坑(持续更新)
1.psutil包,aix环境下,如果进程命令过长的话,程序无法取得完整的进程命令,测试代码如下 import psutil proc=psutil.Process(11534558) pidDict ...