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 ...
随机推荐
- 《Two Dozen Short Lessons in Haskell》所有习题的索引
<Two Dozen Short Lessons in Haskell>(Copyright © 1995, 1996, 1997 by Rex Page,有人翻译为Haskell二十四学 ...
- 在O(N)时间内求解 正数数组中 两个数相加的 最大值
一,问题描述 给定一个正数数组arr(即数组元素全是正数),找出该数组中,两个元素相加的最大值,其中被加数的下标大于加数的下标.由加法运算的可逆性,j >i 这个条件可以去掉. 即求出: max ...
- Kettle基本概念学习
一,理解开发环境与生产环境. 比如,在windows或mac下设计好流程之后,把该设计文件上传到linux集群的机器上执行.那么,在windows下进行的工作即为开发环境,任务具体在linxu机器上执 ...
- android app与服务器交互
package mydemo.mycom.demo2.service; import org.apache.http.HttpResponse; import org.apache.http.Name ...
- SQL Server 2008“备份集中的数据库备份与现有的数据库不同”解决方法
对于SQL Server 2008,有几个地方是要注意的,比方在还原数据库时,不像2000里边将数据库和文件区分的很细, 统一均为文件,这就使还原的数据库文件制定为. bak.那么想还原2000的数据 ...
- img格式镜像转ISO格式
在做汇编学习时,需要用比较老的Windows XP来进行调试学习,因此找了最老的Windows XP(CN_WINXP_PRO_ISO,无SP版本 ),下载后发现镜像文件格式是img的,而virtua ...
- group by与avg(),max(),min(),sum()函数的关系
数据库表: create table pay_report( rdate varchar(8), --日期 region_id varchar(4), --地市 ...
- yum安装包另存
yum install --downloadonly --downloaddir=/tmp <package-name> 1.yum已安装的列表 yum list installed
- Python 对图片进行人脸识别
import cv2 def detect(path): img = cv2.imread(path) cascade = cv2.CascadeClassifier("/vagrant/d ...
- TeamCity 和 Nexus 的使用
参考:http://www.jianshu.com/p/255a484555d9 TeamCity 安装部署(Linux 环境) 在我讲之前,如果你英文还可以,就到官网这里看下: Installati ...