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 ...
随机推荐
- 用遗传算法解决TSP问题
浅谈遗传算法:https://www.cnblogs.com/AKMer/p/9479890.html Description \(小m\)在踏上寻找\(小o\)的路程之后不小心碰到了大魔王\(fat ...
- android开发中 解决服务器端解析MySql数据时中文显示乱码的情况
首先,还是确认自己MySql账户和密码 1.示例 账户:root 密码:123456 有三个字段 分别是_id .username(插入有中文数据).password 1)首先我们知道 ...
- HDU3018:Ant Trip(欧拉回路)
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- java基础知识(2)---语法基础
二:java语法基础: 1,关键字:其实就是某种语言赋予了特殊含义的单词. 保留字:其实就是还没有赋予特殊含义,但是准备日后要使用过的单词. 2,标示符:其实就是在程序中自定义的名词.比如类名,变量名 ...
- hibernate HQL查询
hql(都要在事务中完成)session.beginTransaction();session.getTransaction().commit(); session.beginTransaction( ...
- linux日常管理-top动态查看负载
动态查看负载命令,具体哪个程序,哪个进程造成的系统负载. top 回车查看 3秒更新一次 第一行和uptime和w第一行显示的一样. CPU使用率,us sy 内存相关,Mem 一共多少,使用了多少, ...
- Ruby环境搭建与“Hello World”
Ruby的环境搭建比较简单,在http://rubyinstaller.org/downloads/可以得到Ruby的安装包, 安装过程没什么问题.安装完成之后需要配置一下环境变量: 在PATH中填入 ...
- ABCD四个人说真话的概率都是1/3。假如A声称B否认C说D是说谎了,那么D说过的那句话真话的概率是多少
ABCD四个人说真话的概率都是1/3.假如A声称B否认C说D是说谎了,那么D说过的那句话 真话的概率是多少 记"A声称B否认C说D说谎"为X,那么由贝叶斯公式,所求的 P(D真)P ...
- 线程中t.setdaemon(), t.jion(), t.start的使用
import threading import time def f0(): pass def f1(a1,a2): time.sleep(10) f0() ") t1 = threadin ...
- 用C语言实现一个公用库函数void * memmove(void *dest,const void *src,size_t n)
用C语言实现一个公用库函数void * memmove(void *dest,const void *src,size_t n). 该函数的功能是拷贝src所指的内存内容前n个字节到dest所指的地址 ...