Atcoder Contest 015 E
题目大意
给定一条数轴. 数轴上有\(n\)个点, 它们的初始位置给定, 移动速度也给定. 从0时刻开始, 所有点都从其初始位置按照其移动速度向数轴正方向移动. 这些点开始时可能是红色的, 也可能是黑色的, 这由你来决定, 也就是说这些点的颜色状态有\(2^n\)种; 假如某一时刻一个黑色的点与一个红色的点处于同一位置时, 则这个黑色的点会变成红色. 问有这\(2^n\)中状态中有多少满足最终所有点都变成红色.
\(n \le 10^5\), 点的速度和位置\(\le 10^9\)
题解
开始时我们默认所有点都是黑色的.
考虑把一个点变成红色会有什么样的影响: 首先是速度比他快并且起始位置在它后面的点会追上它, 因而变成红色; 同时速度比它慢且起始位置在它前面的点会被它追上, 因此也会变成红色; 但我们发现还有一些点也会变成红色: 比如说一个起始位置在后面的点追及后变成红色, 这之后可能继续追及一些点, 因此一些起始位置在这个点前面且速度比它快的点也有可能变成红色.
我们考虑把所有点按照其速度从小到大排序, 对于一个点我们把它变成红色, 那么我们找到最左边的一个起始位置大于等于它的点, 再找到最右边的起始位置小于等于它的点, 则我们发现这两个点之间的区间中, 所有点都能与之一起变成红色. 线段树优化DP即可.
这份代码目前还是WA的, 问题主要在于题目没有说清楚对于位置相同以及速度相同的点应该怎么处理.
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
namespace Zeonfai
{
inline int getInt()
{
int a = 0, sgn = 1; char c;
while(! isdigit(c = getchar())) if(c == '-') sgn *= -1;
while(isdigit(c)) a = a * 10 + c - '0', c = getchar();
return a * sgn;
}
}
using namespace std;
const int N = (int)2e5, MOD = (int)1e9 + 7;
int n;
int mn[N + 1], mx[N + 1];
struct point
{
int v, pos;
inline int operator <(const point &a) const {return v == a.v ? pos < a.pos : v < a.v;} // 注意速度相同的处理
}p[N + 1];
struct section
{
int L, R;
inline int operator <(const section &a) const {return R == a.R ? L < a.L : R < a.R;}
}sec[N + 1];
struct binaryIndexedTree
{
int a[N + 2];
inline binaryIndexedTree() {memset(a, 0, sizeof(a));}
inline void modify(int pos, int x)
{
for(int i = pos + 1; i <= n + 1; i += i & - i) a[i] = (a[i] + x) % MOD;
}
int query(int pos)
{
int res = 0;
for(int i = pos + 1; i; i -= i & - i) res = (res + a[i]) % MOD;
return res;
}
inline int query(int L, int R) {return (query(R) - query(L - 1) + MOD) % MOD;}
}BIT;
int main()
{
#ifndef ONLINE_JUDGE
freopen("incubator.in", "r", stdin);
freopen("incubator.out", "w", stdout);
#endif
using namespace Zeonfai;
n = getInt();
for(int i = 1; i <= n; ++ i) p[i].pos = getInt(), p[i].v = getInt();
sort(p + 1, p + n + 1);
for(int i = 1; i <= n; ++ i) mx[i] = i == 1 ? p[i].pos : max(mx[i - 1], p[i].pos);
for(int i = n; i; -- i) mn[i] = i == n ? p[i].pos : min(mn[i + 1], p[i].pos);
for(int i = 1; i <= n; ++ i)
{
int L = 1, R = i - 1, pos = i;
while(L <= R) if((mx[L + R >> 1] > p[i].pos) & (p[L + R >> 1].v != p[i].v)) {pos = L + R >> 1; R = (L + R >> 1) - 1;} else L = (L + R >> 1) + 1;
sec[i].L = pos;
L = i + 1; R = n; pos = i;
while(L <= R) if((mn[L + R >> 1] < p[i].pos) & (p[L + R >> 1].v != p[i].v)) {pos = L + R >> 1; L = (L + R >> 1) + 1;} else R = (L + R >> 1) - 1;
sec[i].R = pos;
}
sort(sec + 1, sec + n + 1);
BIT.modify(0, 1);
for(int i = 1; i <= n; ++ i)
BIT.modify(sec[i].R, BIT.query(sec[i].L - 1, sec[i].R));
printf("%d\n", BIT.query(n, n));
}
/*
5
4 9
3 6
8 1
9 2
5 1
*/
Atcoder Contest 015 E的更多相关文章
- [atcoder contest 010] F - Tree Game
[atcoder contest 010] F - Tree Game Time limit : 2sec / Memory limit : 256MB Score : 1600 points Pro ...
- AtCoder Grand Contest 015 C - Nuske vs Phantom Thnook
题目传送门:https://agc015.contest.atcoder.jp/tasks/agc015_c 题目大意: 现有一个\(N×M\)的矩阵\(S\),若\(S_{i,j}=1\),则该处为 ...
- AtCoder Grand Contest 015 E - Mr.Aoki Incubator
题目传送门:https://agc015.contest.atcoder.jp/tasks/agc015_e 题目大意: 数轴上有\(N\)个点,每个点初始时在位置\(X_i\),以\(V_i\)的速 ...
- Atcoder Grand Contest 015 F - Kenus the Ancient Greek(找性质+乱搞)
洛谷题面传送门 & Atcoder 题面传送门 一道难度 Au 的 AGC F,虽然看过题解之后感觉并不复杂,但放在现场确实挺有挑战性的. 首先第一问很简单,只要每次尽量让"辗转相除 ...
- AtCoder Grand Contest 015
传送门 A - A+...+B Problem 题意:n个数最大值a,最小值b,求和的可能数量. #include<cstdio> #include<algorithm> us ...
- AtCoder Grand Contest 015 题解
A - A+...+B Problem 常识 Problem Statement Snuke has N integers. Among them, the smallest is A, and th ...
- AtCoder Grand Contest 015题解
传送门 \(A\) 找到能达到的最大的和最小的,那么中间任意一个都可以被表示出来 typedef long long ll; int n,a,b;ll res; int main(){ scanf(& ...
- Petrozavodsk Winter-2018. AtCoder Contest. Problem I. ADD, DIV, MAX 吉司机线段树
题意:给你一个序列,需要支持以下操作:1:区间内的所有数加上某个值.2:区间内的所有数除以某个数(向下取整).3:询问某个区间内的最大值. 思路(从未见过的套路):维护区间最大值和区间最小值,执行2操 ...
- HZOI20190813 B,任(duty)
题面:去一个神奇的网页:https://www.cnblogs.com/Juve/articles/11352426.html 听说打O(nmq)有70 但是显然博主只有50分 考点:前缀和的综合应用 ...
随机推荐
- 网络流24题:P2762 太空飞行计划问题
P2762 太空飞行计划问题 题目背景 题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,E ...
- Python框架之Django学习笔记(十三)
Django站点管理(续1) 上次介绍了Django的站点管理的一些基础知识,这次再来深入了解一下Django的站点管理. Admin是如何工作的: 在幕后,管理工具是如何工作的呢? 其实很简单. 当 ...
- 转行自学 Java 之路的纪念册
前言: 最近在重读<小狗钱钱>,我对其中的"成功日记"概念特别深刻,偶尔也会记一记“成功日记”. 想了想人生走找到今天,阶段性“成功日记”有没有呢? 有的!几年前的一篇 ...
- PyInstaller打包python脚本
用python写的工具写好了,想打包然后发给测试同事使用,最后选择了PyInstaller,支持Windows.Linux.OS X,支持打包成一个文件夹或单个EXE文件. 我是直接在线安装的,在 ...
- CentOS7安装Code::Blocks
在CentOS7上安装Codelocks的过程. 1.安装gcc,需要c和c++两部分,默认安装下,CentOS不安装编译器的,在终端输入以下命令即可yum install gccyum instal ...
- python re模块详解
re模块 re模块使用python拥有全部的正则表达式功能 1 2 3 4 re.I(re.IGNORECASE): 忽略大小写(括号内是完整写法) re.M(MULTILINE):(多行模式,改变 ...
- 1020 PAT
在编译器上运行没问题,提交显示编译错误 # include<stdio.h> # include<stdlib.h> struct YB { int a,b; double c ...
- Java给各个方法记录执行时间
Java给各个方法记录执行时间 long startTime = System.currentTimeMillis();...//要测试时间的方法LoggerFactory.getLogger(Bas ...
- iOS开发UI篇—自定义layer
一.第一种方式 1.简单说明 以前想要在view中画东西,需要自定义view,创建一个类与之关联,让这个类继承自UIView,然后重写它的DrawRect:方法,然后在该方法中画图. 绘制图形的步骤: ...
- git merge / rebase 分支的新建与合并
merge https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%9A%84%E6%96%B0%E5% ...