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 树状数组的更多相关文章

  1. Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀、最值

    http://codeforces.com/problemset/problem/12/D 这里的BIT查询,指的是查询[1, R]或者[R, maxn]之间的最值,这样就够用了. 设三个权值分别是b ...

  2. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数

                                                                    E. Infinite Inversions               ...

  6. 【Codeforces Round #433 (Div. 1) C】Boredom(树状数组)

    [链接]h在这里写链接 [题意] 给你一个n*n的矩阵. 其中每一列都有一个点. 任意两个点构成了矩形的两个对角点 ->即任意两个点确定了一个矩形. ->总共能确定n*(n-1)/2个矩形 ...

  7. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  8. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  9. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

随机推荐

  1. 洛谷【P1358】扑克牌

    我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:https://www.luogu.org/problemnew/show/P ...

  2. gradle项目搭建

    一.gradle安装 1.安装JDK,这个就不用说了 2.下载gradle发布文件,下载地址:http://gradle.org/gradle-download/可以下载完整版或者简洁版都可以 3.解 ...

  3. IOS的设计模式

    对象创建 原型(Prototype) 使用原型实例指定创建对象的种类,并通过复制这个原型创建新的对象. NSArray *array = [[NSArray alloc] initWithObject ...

  4. HTML表格中<td scope="col">与<td scope="row">的含义

    HTML表格中<td scope="col">与<td scope="row">的含义 表格中 <td scope="c ...

  5. ssh功能模块——paramiko

    参考官网文档:http://docs.paramiko.org/

  6. KickStart安装CentOS,同时安装和配置hadoop

    声明:这篇文章是前面是拾人牙慧,我是结合 http://www.111cn.net/sys/linux/59969.htm 和 http://www.cnblogs.com/mchina/p/cent ...

  7. 业务逻辑:完成基于CRM地址完全匹配的自动分单业务逻辑

    思路: 后台系统的业务接口服务处理接收到的数据并使用Webservice技术来远程调用CRM系统的业务接口服务来进行定区的查询操作,随后从该定区中匹配一个快递员来分配工单并发送短信通知取件 操作步骤: ...

  8. Appium 在 Android UI 测试中的应用

    原文地址:https://blog.coding.net/blog/Appium-Android-UI Android 测试工具与 Appium 简介 Appium 是一个 C/S 架构的,支持 An ...

  9. 7.23实习培训日志-JDBC

    总结 今天下午考试,JDBC,这个本身很简单,但是需要我们Dockerfile+Docker Compose运行,这个东西就很复杂.原来学习时没有怎么看,这一次就很懵,完全不知道怎么弄,反正环境都没有 ...

  10. CCS中如何新建Platform以及调用

    新建Platform: Debug模式下,选择tools -> RTSC Tools -> Platform -> New,根据自己的需要选择Platform保存的路径以及对应的芯片 ...