Bzoj3631 JLOI2014 松鼠的新家

2021-07-11 08:12:27 字數 1073 閱讀 7216

solution

先考慮在序列上的做法。注意到是先處理完所有修改後才做詢問,那麼每次區間加上乙個數時就只須在左右端點分別打上乙個+和-的標記,最後詢問時將整個序列從左到右掃一遍即可。

樹上同理。

#include

#include

#include

#include

using

namespace

std;

const

int maxn = 300005;

struct edge

edge(int _x,int _y,int _nt): x(_x) , y(_y) , next(_nt){}

}e [maxn << 1];

int head[maxn] , tot = 0;

inline

void addedge(int x,int y)

int top[maxn],p[maxn],siz[maxn],son[maxn],fa[maxn],dep[maxn];

int n,m,t;

int tag[maxn][2],a[maxn],c[maxn],s[maxn];

void dfs1(int x)

}void dfs2(int x,int chain)

}int sum = 0;

void dfs3(int x)

int main()

dep[1]=1;

dfs1( 1 );

dfs2( 1 , 1 );

for(int x,y,i = 1 ; i <= n-1 ;i++)

if( dep[x] > dep[y] ) swap( x , y );

tag[x][0]++;

tag[y][1]++;

}for(int i = 1 ; i <= n ; i++)

if( i == top[i] ) dfs3(i);

for(int i = 1 ; i <= n ; i++)

printf("%d\n",s[i]-c[i]);

}

BZOJ3631 JLOI2014 松鼠的新家

題目大意 從編號1到n遍歷圖 中間經過點不算遍歷過 求每個點經過了幾次 樹剖,每次i到i 1都相當於一次鏈上修改,最後單點查詢就行。include include include include define n 300009 define inf 0x7fffff define ll long l...

BZOJ3631 JLOI2014 松鼠的新家

松鼠的新家是一棵樹,前幾天剛剛裝修了新家,新家有n個房間,並且有n 1根樹枝連線,每個房間都可以相互到達,且倆個房間之間的路線都是唯一的。天哪,他居然真的住在 樹 上。松鼠想邀請 前來參觀,並且還指定乙份參觀指南,他希望 能夠按照他的指南順序,先去a1,再去a2,最後到an,去參觀新家。可是這樣會導...

BZOJ3631 JLOI2014 松鼠的新家

bzoj3631 jloi2014 松鼠的新家 松鼠的新家是一棵樹,前幾天剛剛裝修了新家,新家有n個房間,並且有n 1根樹枝連線,每個房間都可以相互到達,且倆個房間之間的路線都是唯一的。天哪,他居然真的住在 樹 上。松鼠想邀請 前來參觀,並且還指定乙份參觀指南,他希望 能夠按照他的指南順序,先去a1...