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 ...
随机推荐
- 关于系统中:/dev/mem
1)参考:https://blog.csdn.net/lsn946803746/article/details/52948036 博主:lsn946803746 2)参考:https://blog ...
- ruby中特殊的全局变量
全局变量:由$开头,可以在程序的任何位置访问到.在初始化前,全局变量有一个特殊的值 nil. 这里列出了一些以$打头并跟单个字符的特殊变量,包括主要的系统变量以及它们的含义: $! 最近一次的错误信息 ...
- oracle--存储过程2--bk
oracle存储过程demo1---无返回值的存储过程: /* 写一个过程,可以向book表添加书 */ create table book( id number(4), book_name varc ...
- Spring Boot 高效数据聚合之道
项目地址和示例代码: https://github.com/lvyahui8/spring-boot-data-aggregator 背景 接口开发是后端开发中最常见的场景, 可能是RESTFul接口 ...
- Umbraco遇到的问题解决
在本地VS2015运行公司的Corporate website时,有几个页面出现错误如下: 但事实是那个,这几个View都是存在的.弄了半天也没有能够解决.后来看到这个blog: https://ou ...
- 20169201 2016-2017-2 实验二《Java面向对象程序设计》
实验一:程序设计中临时变量的使用 代码托管 1.删除数组中的元素5 for(int i = 4; i < arr.length - 1; i ++){ arr[i] = arr[i + 1]; ...
- redis集群搭建踩坑笔记
推荐参考教程:https://blog.csdn.net/pucao_cug/article/details/69250101 错误: from /usr/lib/ruby/2.3.0/rubygem ...
- ASP.NET jquery 获取服务器控件ID
一般方法: jQuery("#txtUserName").val(); 如果页面加载了母版页或者自定义控件:该页面的ID有可能会被篡改(可能是因为避免控件ID冲突的机制),因此强烈 ...
- vue 绑定属性(index)
<el-menu-item v-for="item in links" :key="item.id" v-bind:index="item.id ...
- jqGrid 跨页选择以及回显的处理
思路:定义全局的array(selectedIds),当列表选中的时候就push进去,当列表取消选中时,将该项从selectedIds中删除 重点:1.列表加载完成时为列表增加复选框,并给每一个che ...