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 ...
随机推荐
- css基础知识二
1.盒模型: 实际宽度:外边距*2+内边距*2+边框*2+内容宽度(注意这点,可解决界面元素轻微浮动问题,如hover有边框,以前没的时候会有轻微浮动) 作用:他规定了网页元素如何显示以及其相互关系 ...
- Project Server调用PSI关闭任务以进行更新锁定任务
/// <summary> /// 锁定和解锁项目任务 /// </summary> /// <param name="projectuid"> ...
- 可定制的分词库——Yaha(哑哈)分词
可定制的分词库——Yaha(哑哈)分词在线测试地址:http://yaha.v-find.com/ 部署于GAE yahademo.appspot.comYaha分词主要特点是把分词过程分成了4个阶段 ...
- 关于使用sklearn进行数据预处理 —— 归一化/标准化/正则化
一.标准化(Z-Score),或者去除均值和方差缩放 公式为:(X-mean)/std 计算时对每个属性/每列分别进行. 将数据按期属性(按列进行)减去其均值,并处以其方差.得到的结果是,对于每个属 ...
- k8s 基础 k8s架构和组件
k8s 的总架构图
- linux日常管理-防火墙selinux
关闭防火墙 SELINUX=disabled 可以是三种状态 # enforcing - SELinux security policy is enforced.打开# permissive - SE ...
- ueditor1.4.3jsp版成功上传图片后却回显不出来与在线管理显示不出图片的解决方案
这是因为路径问题,可以在jsp/config.json这个文件去改路径 通过“imageUrlPrefix”与“imagePathFormat”这两个属性去拼凑路径. “imageUrlPrefix” ...
- mysql查询语句in和exists二者的区别和性能影响
mysql中的in语句是把外表和内表作hash 连接,而exists语句是对外表作loop循环,每次loop循环再对内表进行查询.一直大家都认为exists比in语句的效率要高,这种说法其实是不准确的 ...
- Java进阶之美文共享
2.在Java中如何避免"!=null"式的判空语句? 3.Java问答:终极父类(3) Java问答:终极父类(下) Java问答:终极父类(上) 内存不足:杀死进程还是牺牲 ...
- Matlab2012a下配置LibSVM—3.18
1.下载最新版LibSVM 点击此处打开网页,点击zip file下载最新版的文件并解压放在任何目录下,建议放在安装目录便于查找.如我的文件解压在路径C:\ProgramFiles\MATLAB\R2 ...