题目链接:https://codeforces.com/problemset/problem/101/B
题目大意:
给你很多个公交车的起点和终点,你可以从一个公交车路线上的任何一个点上车,但上车后只能从公交车路线的终点下车,问你从点1到点n有多少种方案。
思路
对于一个公交车站的终点ti,所有可能的起点为si到ti-1,设dp[i]为到达某个点的方案数,则最终点ti的方案数肯定就是这些可以到达他的点的方案数之和。所以用线段树维护区间和,插值更新就好了(树状数组就更加方便了。
还需要离散化,记得在离散化时候将点0插入vector中,保证从0的位置开始,如果一个终点的可能起点包含0,则方案数还要+1;
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int n,m,Rn,Rank[N];
int sum[N];
struct node{
int s,t;
}a[N];
bool cmp(node a,node b){
return a.t<b.t;
}
void se