Contact ATC

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

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

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

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

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define PLL pair<LL, LL>
  7. #define PLI pair<LL, int>
  8. #define PII pair<int, int>
  9. #define SZ(x) ((int)x.size())
  10. #define ull unsigned long long
  11.  
  12. using namespace std;
  13.  
  14. const int N = 2e5 + ;
  15. const int inf = 0x3f3f3f3f;
  16. const LL INF = 0x3f3f3f3f3f3f3f3f;
  17. const int mod = 1e9 + ;
  18. const double eps = 1e-;
  19. const double PI = acos(-);
  20.  
  21. struct Bit {
  22. int a[N];
  23. void init() {
  24. memset(a, , sizeof(a));
  25. }
  26. void modify(int x, int v) {
  27. for(int i = x; i < N; i += i & -i)
  28. a[i] += v;
  29. }
  30. int sum(int x) {
  31. int ans = ;
  32. for(int i = x; i; i -= i & -i)
  33. ans += a[i];
  34. return ans;
  35. }
  36. int query(int L, int R) {
  37. if(L > R) return ;
  38. return sum(R) - sum(L - );
  39. }
  40. };
  41.  
  42. struct Node {
  43. Node(LL a, LL b) : a(a), b(b) {}
  44. bool operator < (const Node& rhs) const {
  45. return a * rhs.b < rhs.a * b;
  46. }
  47. bool operator == (const Node& rhs) const {
  48. return a * rhs.b == rhs.a * b;
  49. }
  50. void print() {
  51. printf("%.5f ", 1.0 * a / b);
  52. }
  53. LL a, b;
  54. };
  55.  
  56. int n, w, x[N], v[N];
  57. LL ans = ;
  58. vector<PII> vc[];
  59. vector<Node> hs;
  60. Bit bit;
  61.  
  62. bool cmp(PII& a, PII& b) {
  63. if(a.fi == b.fi) return a.se < b.se;
  64. return a.fi > b.fi;
  65. }
  66.  
  67. LL solve(vector<PII>& vc) {
  68. bit.init();
  69. LL ans = ;
  70. sort(vc.begin(), vc.end(), cmp);
  71. for(int i = ; i < SZ(vc); i++) {
  72. ans += bit.sum(vc[i].se);
  73. bit.modify(vc[i].se, );
  74. }
  75. return ans;
  76. }
  77.  
  78. int main() {
  79. scanf("%d%d", &n, &w);
  80. for(int i = ; i <= n; i++) {
  81. scanf("%d%d", &x[i], &v[i]);
  82. if(x[i] < ) {
  83. hs.push_back(Node(-x[i], v[i] + w));
  84. hs.push_back(Node(-x[i], v[i] - w));
  85. } else {
  86. hs.push_back(Node(x[i], w - v[i]));
  87. hs.push_back(Node(x[i], -w - v[i]));
  88. }
  89. }
  90. sort(hs.begin(), hs.end());
  91. hs.erase(unique(hs.begin(), hs.end()), hs.end());
  92. for(int i = ; i <= n; i++) {
  93. if(x[i] < ) {
  94. int L = lower_bound(hs.begin(), hs.end(), Node(-x[i], v[i] + w)) - hs.begin() + ;
  95. int R = lower_bound(hs.begin(), hs.end(), Node(-x[i], v[i] - w)) - hs.begin() + ;
  96. vc[].push_back(mk(L, R));
  97. } else {
  98. int L = lower_bound(hs.begin(), hs.end(), Node(x[i], w - v[i])) - hs.begin() + ;
  99. int R = lower_bound(hs.begin(), hs.end(), Node(x[i], -w - v[i])) - hs.begin() + ;
  100. vc[].push_back(mk(L, R));
  101. }
  102. }
  103. ans += solve(vc[]);
  104. ans += solve(vc[]);
  105. ans += 1ll * SZ(vc[]) * SZ(vc[]);
  106. bit.init();
  107. for(auto& t : vc[]) bit.modify(t.se, );
  108. for(auto& t : vc[]) ans -= bit.sum(t.fi - );
  109. bit.init();
  110. for(auto& t : vc[]) bit.modify(t.fi, );
  111. for(auto& t : vc[]) ans -= bit.query(t.se + , N - );
  112. printf("%lld\n", ans);
  113. return ;
  114. }
  115.  
  116. /*
  117. */

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. Composer 安装和使用

    1.linux下安装 curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer ...

  2. jaxp实现对xml文档的增,删,改,查操作(附源码)浅析

    jaxp,属于javase中的一部分.是对xml进行解析的一个工具类: 既然说到这里,还是讲全一点,讲讲上面说到的xml的解析技术. xml的一个标记型文档. 在html的层级结构中,它会在内存中分配 ...

  3. Python 升级致yum 问题,pip 异常

    升级 Python 导致 yum 和 pip 异常: 一些storm 和 自定义项目 需要升级python版本:Linux 系统默认是2.6 版本 ,所以需要根据业务进行升级操作:Python 官方下 ...

  4. js 判断身份证好是否合法

    function cidInfo(sId){ var info="" //if(!/^\d{17}(\d|x)$/i.test(sId))return false; sId=sId ...

  5. android AysncTask使用

    1.继承AysncTask类 例子: class downloadTask extends AsyncTask<Void,Integer,Boolean> 第一个参数是传入的参数 第二个参 ...

  6. css 背景图片自适应元素大小

    一.一种比较土的方法,<img>置于底层. 方法如下: CSS代码: HTML: <img src="背景图片路径" /> <span>字在背景 ...

  7. 如何将SVN仓库转换为Git仓库

    按如下步骤操作就可以将SVN仓库完整的转换为Git仓库: 1) 将远程SVN仓库搬到本地(这一步主要是为了提高转换的速度,也可以忽略)     参考这篇文章: http://rongjih.blog. ...

  8. NandFlash和iNand

    nand 1.nand的单元组织:block与page(大页Nand与小页Nand)(1)Nand的页和以前讲过的块设备(尤其是硬盘)的扇区是类似的.扇区最早在磁盘中是512字节,后来也有些高级硬盘扇 ...

  9. HTMl学习笔记02-编辑器

    工欲善其事,必先利其器 使用专业HTML编辑器来编辑HTML,推荐使用Notepad++,中文界面. 在Notepad++安装完成后,点击文件>新建.语言>H中选择HTML 在新建的文件输 ...

  10. python2.7源码或第三方包里埋藏的坑(持续更新)

    1.psutil包,aix环境下,如果进程命令过长的话,程序无法取得完整的进程命令,测试代码如下 import psutil proc=psutil.Process(11534558) pidDict ...