NOIP复习V-DCC逛公园I

琥珀色黄昏像糖在很美的远方,思念跟影子在傍晚一起被拉长……
小 B 带着 GF 去逛公园,公园一共有 n 个景点,标号为 1 . . . n。景点之间有 m 条路径相连。
小 B 想选择编号在一段区间 [l, r] 内的景点来游玩,但是如果这些景点的诱导子图形成了环,那么 GF 将会不高兴。
小 B 给出很多个询问 [x, y],想让你求有多少个区间 [l, r] 满足 x ≤ l, r ≤ y 且不会使 GF不高兴。
考试的时候写了一个BCC得了80分,但实际上这道题是一个V-DCC,毕竟是仙人掌嘛。
首先用V-DCC预处理出所有的环,然后更新一个点最远可以到哪里,这是显然单调的
二分查询的左端点。
最后求答案的时候把范围内的用前缀和求了,其余的用等差数列求和求出。

#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
const int N=3e5+100;
inline void read(int &x){
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	x*=f;
}
struct Front_star{
	int u,v,nxt;
}e[N<<1];
int cnt=1;
int first[N];
void add(int u,int v){
	++cnt;
	e[cnt].u=u;
	e[cnt].v=v;
	e[cnt].nxt=first[u];
	first[u]=cnt;
}
//
int n,m;
struct Node{
	int Mn,Mx;
}G[N];
//
int dfn[N];
int low[N];
int siz[N];
int Belong[N];
int vis[N<<1];
stackS;
int dcc=0;
int tot=0;
void Tarjan(int u,int fat){
	dfn[u]=low[u]=++tot;
	S.push(u);
	for(int i=first[u];i;i=e[i].nxt){
		if((i^1)==fat)continue;
		int v=e[i].v;
		if(!dfn[v]){
			Tarjan(v,i);
			low[u]=min(low[u],low[v]);
			if(dfn[u]=l)cout<

转载于:https://www.cnblogs.com/Leo-JAM/p/10079054.html

你可能感兴趣的:(NOIP复习V-DCC逛公园I)