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 ...
随机推荐
- Solr之.net操作
http://www.cnblogs.com/zhangweizhong/category/771055.html 插入: SolrNet.Startup.Init<Movie>(&quo ...
- jenkins配置sonarqube
jenkins配置sonarqube 下载插件SonarQube Scanner for Jenkins 在系统管理系统设置中选择 SonarQube servers 配置服务器名称.访问URL地址, ...
- 11、Logback日志框架介绍和SpringBoot整合实战 2节课
1.新日志框架LogBack介绍 简介:日志介绍和新日志框架Logback讲解 1.常用处理java的日志组件 slf4j,log4j,logback,common-logging 等 ...
- ubuntu 系统关键指令
1. 查看系统版本号 cat /etc/issue uname -a cat /proc/version 2. linux 32/64 bit? getconf LONG_BIT 3. dpkg 的命 ...
- .Net Core中使用RabbitMQ
(1).引入依赖 RabbitMQ.Client (2).编写发布者代码 var connectionFactory = new ConnectionFactory() { HostName=&quo ...
- SpringBoot处理静态资源的两种方式
静态资源是指----> CSS.JS之类的文件 首先创建SpringBoot Web项目 添加Spring Boot Web Starter <dependency> <gro ...
- SpringMVC使用Redis作为缓存提供者
(1)pom添加依赖项 <dependency> <groupId>org.springframework.data</groupId> <artifactI ...
- 搭建Modelsim SE仿真环境-使用do文件仿真
本章我们介绍仿真环境搭建是基于Modelsim SE的.Modelsim有很多版本,比如说Modelsim-Altera,但是笔者还是建议大家使用Modelsim-SE,Modelsim-Altera ...
- Difference between plt.draw() and plt.show() in matplotlib
Difference between plt.draw() and plt.show() in matplotlib down voteaccepted plt.show() will display ...
- pt-online-schema-change VS oak-online-alter-table
前言 在上篇文章中提到了MySQL 5.6 Online DDL,如果是MySQL 5.5的版本在DDL方面是要付出代价的,虽然已经有了Fast index Creation,但是在添加字段还是会锁表 ...