Codeforces Beta Round #79 (Div. 1 Only) B. Buses 树状数组
http://codeforces.com/contest/101/problem/B
给定一个数n,起点是0 终点是n,有m两车,每辆车是从s开去t的,我们只能从[s,s+1,s+2....t-1]处上车,从t处下车。,
问能否去到点n,求方案数
设L[x]表示有多少辆车能够到达x处。
只能从t处下车:说明只能单点更新,对于没辆车x,在区间[s,s+1,s+2....t-1]内上车是可以得,那么有多少辆车呢?明显就是∑区间里能到达的点。然后单点更新t即可
数据大,明显不能到达的点是没用的,离散化一下即可。
坑点就是:因为车是无序的,所以应该优先处理最快下车的点。这样就能对后面进行更新
注意树状数组哪里也要取模
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 3e5 + ;
const int MOD = 1e9 + ;
int n, to;
LL c[maxn];
int lowbit (int x) {
return x&(-x);
}
void add (int pos,LL val) {
while (pos<=to + ) {
c[pos] += val;
c[pos] %= MOD;
pos += lowbit(pos);
}
return ;
}
LL get_sum (int pos) {
LL ans = ;
while (pos) {
ans += c[pos];
ans %= MOD;
pos -= lowbit(pos);
}
return ans;
}
struct node {
int s, t;
}a[maxn];
bool cmp (node a, node b) {
if (a.t != b.t) {
return a.t < b.t;
} else {
return a.s < b.s;
}
}
set<int>ss;
map<int,int>pos;
LL ways[maxn];
void work() {
cin >> n;
int m;
cin >> m;
int numzero = ;
int numlast = ;
for (int i = ; i <= m; ++i) {
scanf("%d%d", &a[i].s, &a[i].t);
if (a[i].s == ) numzero++;
if (a[i].t == n) numlast++;
}
if (numzero == || numlast == ) {
cout << "" << endl;
return;
}
sort(a + , a + + m, cmp);
for (int i = ; i <= m; ++i) {
ss.insert(a[i].s);
ss.insert(a[i].t);
}
for (set<int>::iterator it = ss.begin(); it != ss.end(); ++it) {
if (pos[*it] == ) {
pos[*it] = ++to;
}
}
add(, );
for (int i = ; i <= m; ++i) {
int toa = pos[a[i].s];
int tob = pos[a[i].t];
LL t = (get_sum(tob - ) - get_sum(toa - ) + MOD) % MOD;
add(tob, t);
}
LL ans = get_sum(pos[n]) - get_sum(pos[n] - );
if (ans < ) ans += MOD;
cout << ans << endl;
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}
Codeforces Beta Round #79 (Div. 1 Only) B. Buses 树状数组的更多相关文章
- Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀、最值
http://codeforces.com/problemset/problem/12/D 这里的BIT查询,指的是查询[1, R]或者[R, maxn]之间的最值,这样就够用了. 设三个权值分别是b ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Round #381 (Div. 2) D dfs序+树状数组
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Beta Round #14 (Div. 2) D. Two Paths 树的直径
题目链接: http://codeforces.com/contest/14/problem/D D. Two Paths time limit per test2 secondsmemory lim ...
- Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数
E. Infinite Inversions ...
- 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)
[链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
随机推荐
- 不同类型input尺寸设置区别
最近发现为不用类型的input设置相同的尺寸,却得到了不一样的尺寸结果.发现不同类型的input的height和width竟然含义不同.在此小整理一下. (1)button类型 规律 button类型 ...
- Poj 1504 Adding Reversed Numbers(用字符串反转数字)
一.题目大意 反转两个数字并相加,所得结果崽反转.反转规则:如果数字后面有0则反转后前面不留0. 二.题解 反转操作利用new StringBuffer(s).reverse().toString() ...
- 【转】 Pro Android学习笔记(五七):Preferences(1):ListPreference
目录(?)[-] 例子1ListPreference小例子 定义一个preferences XML文件 继承PreferenceActivity 用户定制偏好的读取 第一次运行时设置缺省值 设置Cat ...
- 通过设置swift中container的ACL提供匿名访问及用户授权读取服务
在上层使用swift提供的云存储服务的过程中,提出了无需验证的使用需求. 在参考了:http://my.oschina.net/alanlqc/blog/160196(curl命令操作) 官方文档: ...
- ES6学习之对象扩展
简介表示法(直接写入变量和函数,作为对象的属性和方法) let x = "test" let obj={ x, //属性名为变量名,属性值为变量值 y(){console.log( ...
- jdbc 新认识
以前一直用jdbc,没有深入看看,原来jdbc是java自己的接口规范,db厂商按照接口进行开发对应的驱动,jdbc可以获取db中的元信息,执行sql,获取结果,操作db等等.示例如下. public ...
- python 基础 列表 小例子
存主机ip到列表 host_list=[] netip='192.168.1' for hostip in range(1,254): ip = netip +str(hostip) host_lis ...
- java数据库连接模板代码通用收集
package org.lxh.dbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLE ...
- Unity堆内存优化
unity中减少堆内存分配以减少垃圾回收处理:只有局部变量且为值类值的变量是从stack栈中分配内存,其它所有情况都是从heap堆中分配内在.* 缓存获取到的数据.* 频繁被调用的函数中尽量少的分配空 ...
- Freemarker01
1 如何使用freemarker 1.1 导包 freemarker-2.3.19.jar 1.2 创建一个ftl文件作为模板 1.3 创建一个方法来将ftl模板和数据组合起来 2 利用maven实现 ...