当前位置: 首页 > news >正文

网站的创新点有哪些郑州中原区最新消息

网站的创新点有哪些,郑州中原区最新消息,主页网站模板,物联网方案其实题目就是每次询问一个节点 在这个节点的基础上往下继续遍历t的深度&#xff0c;在这个遍历的过程中找一个最大值就行了 其实这个题目数据非常水&#xff0c;直接暴力就可以过了 下面是别人过的代码 #include<bits/stdc.h> using namespace std; const int mxn5e…

其实题目就是每次询问一个节点

在这个节点的基础上往下继续遍历t的深度,在这个遍历的过程中找一个最大值就行了 

其实这个题目数据非常水,直接暴力就可以过了

下面是别人过的代码

#include<bits/stdc++.h>
using namespace std;
const int mxn=5e5+10;
#define ll long long
ll n,m,a[mxn];
vector<ll> v[mxn];
ll dfs(int t,int x){ll ans=a[x];if(t==0) return ans;for(auto i:v[x])ans=max(dfs(t-1,i),ans);return ans;
}
int main(){ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);cin>>n;for(int i=1;i<=n;i++) cin>>a[i];for(int x,y,i=1;i<n;i++)cin>>x>>y,v[x].push_back(y);cin>>m;for(int t,x,i=1;i<=m;i++){cin>>t>>x;cout<<dfs(t,x)<<"\n";}return 0;
}

但是我这还是说一下数据结构维护的做法

首先先dfs一次求dfn序,每个节点子树的sz,每个节点的深度dep

然后建一颗可持久化线段树

dep从1-n依次把每个点的权值插入到dfn序中,同时root维护的时当前dep插入完后头节点是啥

也就是在root[x]中已经把dep从1-x中的所有的值插入进去了

然后询问的时候询问在root[min(n, dep[x] + t)] 从dfn[x]到dfn[x] + sz[x] - 1

因为你最深的深度是min(n, dep[x] + t) 此时root已经把低于最深的深度的所以数都插入进去了

dfn序又帮你把询问的区间给确定了

using namespace std;
const int inf = 0x3f3f3f3f3f3f3f3f, N = 5e5 + 5, mod = 1e9 + 7;
int a[N];
vector<int>q[N], e[N];
int cnt, dep[N], dfn[N];
int sz[N];
void dfs(int x, int fa)
{dfn[x] = ++cnt;dep[x] = dep[fa] + 1;sz[x] = 1;for (auto w : q[x]) {if (w == fa) continue;dfs(w, x);sz[x] += sz[w];}
}
struct Tree
{int l, r, mx;
}tr[N*40];
int idx;
int build(int l, int r)
{int p = ++idx;if (l == r) return p;int mid = l + r >> 1;tr[p].l = build(l, mid), tr[p].r = build(mid + 1, r);return p;
}
void pushup(int p)
{tr[p].mx = max(tr[tr[p].l].mx, tr[tr[p].r].mx);
}
int insert(int p, int l, int r, int x,int val)
{int q = ++idx;tr[q] = tr[p];if (l == r) {tr[q].mx = val;return q;}int mid = l + r >> 1;if (x <= mid)  tr[q].l = insert(tr[p].l, l, mid, x, val);else tr[q].r = insert(tr[p].r, mid + 1, r, x, val);pushup(q);return q;
}
int root[N];
int ask(int p, int L, int R, int l, int r)
{if (l <= L && R <= r) {return tr[p].mx;}int mid = L + R >> 1;int mx = 0;if (l <= mid) mx = max(mx, ask(tr[p].l, L, mid, l, r));if (r > mid) mx = max(mx, ask(tr[p].r, mid + 1, R, l, r));return mx;
}
signed main()
{ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);int n;cin >> n;for (int i = 1; i <= n; i++) {cin >> a[i];}for (int i = 1; i < n; i++) {int u, v;cin >> u >> v;q[u].push_back(v);q[v].push_back(u);}dfs(1, 0);for (int i = 1; i <= n; i++) {e[dep[i]].push_back(i);}root[0] = build(1, n);for (int i = 1; i <= n; i++) {int pre = 0;for (auto w : e[i]) {root[i] = insert(max(root[i - 1],pre), 1, n, dfn[w], a[w]);pre = root[i];}if (root[i] == 0) {root[i] = root[i - 1];}}int m;cin >> m;while (m--){int t, x;cin >> t >> x;cout << ask(root[min(n, dep[x] + t)], 1, n, dfn[x], dfn[x] + sz[x] - 1) << '\n';}
}


文章转载自:
http://dinncothreadworm.zfyr.cn
http://dinncospeedflash.zfyr.cn
http://dinncodent.zfyr.cn
http://dinncozonule.zfyr.cn
http://dinncomylonite.zfyr.cn
http://dinncocateress.zfyr.cn
http://dinncospat.zfyr.cn
http://dinncoconcordant.zfyr.cn
http://dinncocarey.zfyr.cn
http://dinncohoise.zfyr.cn
http://dinncodesultorily.zfyr.cn
http://dinncobennett.zfyr.cn
http://dinncosaloonatic.zfyr.cn
http://dinncodialogic.zfyr.cn
http://dinncomack.zfyr.cn
http://dinncolamarckism.zfyr.cn
http://dinncotipcart.zfyr.cn
http://dinncoennuye.zfyr.cn
http://dinncostipule.zfyr.cn
http://dinncohypodiploid.zfyr.cn
http://dinncofolksinging.zfyr.cn
http://dinncoapostatize.zfyr.cn
http://dinncowritten.zfyr.cn
http://dinncosuperpotency.zfyr.cn
http://dinncoempathetic.zfyr.cn
http://dinncooverwinter.zfyr.cn
http://dinncominium.zfyr.cn
http://dinnconummary.zfyr.cn
http://dinncoasylum.zfyr.cn
http://dinncodisablement.zfyr.cn
http://dinncocurriery.zfyr.cn
http://dinncotoward.zfyr.cn
http://dinncohaemodialysis.zfyr.cn
http://dinncooverstorage.zfyr.cn
http://dinncolark.zfyr.cn
http://dinncoquerulously.zfyr.cn
http://dinncovaporware.zfyr.cn
http://dinncocash.zfyr.cn
http://dinncoorchidotomy.zfyr.cn
http://dinnconotchy.zfyr.cn
http://dinncosulphur.zfyr.cn
http://dinncodialectologist.zfyr.cn
http://dinncotomboyish.zfyr.cn
http://dinncopulj.zfyr.cn
http://dinncodigress.zfyr.cn
http://dinncomislike.zfyr.cn
http://dinncoluke.zfyr.cn
http://dinncoparathyroidectomize.zfyr.cn
http://dinncoused.zfyr.cn
http://dinncogeoponics.zfyr.cn
http://dinncojaboticaba.zfyr.cn
http://dinncolitigious.zfyr.cn
http://dinncokiswahili.zfyr.cn
http://dinncotabes.zfyr.cn
http://dinncoconventicle.zfyr.cn
http://dinncononpartisan.zfyr.cn
http://dinncooveryear.zfyr.cn
http://dinncoperpend.zfyr.cn
http://dinncodeserted.zfyr.cn
http://dinncochevrette.zfyr.cn
http://dinncocineol.zfyr.cn
http://dinncoredundantly.zfyr.cn
http://dinncoylem.zfyr.cn
http://dinncosqualene.zfyr.cn
http://dinncotrublemaker.zfyr.cn
http://dinncoidiorrhythmy.zfyr.cn
http://dinncoweatherology.zfyr.cn
http://dinncocranage.zfyr.cn
http://dinncopseudoalum.zfyr.cn
http://dinncosplay.zfyr.cn
http://dinncoshavecoat.zfyr.cn
http://dinncogroundage.zfyr.cn
http://dinncoinwinter.zfyr.cn
http://dinncoway.zfyr.cn
http://dinncodob.zfyr.cn
http://dinncoovercapacity.zfyr.cn
http://dinncostopwatch.zfyr.cn
http://dinncoverandah.zfyr.cn
http://dinncochariness.zfyr.cn
http://dinncoreddle.zfyr.cn
http://dinncoifpi.zfyr.cn
http://dinncobelgique.zfyr.cn
http://dinncoseptenate.zfyr.cn
http://dinncoreticulitis.zfyr.cn
http://dinncogoy.zfyr.cn
http://dinncoembroglio.zfyr.cn
http://dinncoresegmentation.zfyr.cn
http://dinncotroublesomely.zfyr.cn
http://dinncopolished.zfyr.cn
http://dinncowanderingly.zfyr.cn
http://dinncocashier.zfyr.cn
http://dinncoscrape.zfyr.cn
http://dinncopassbook.zfyr.cn
http://dinncoscantling.zfyr.cn
http://dinncomachinize.zfyr.cn
http://dinncosophistication.zfyr.cn
http://dinncoscepticism.zfyr.cn
http://dinncocounterconditioning.zfyr.cn
http://dinncooperetta.zfyr.cn
http://dinncodecimet.zfyr.cn
http://www.dinnco.com/news/153150.html

相关文章:

  • 网站建设的需求文档搜狗搜索排名优化
  • 网站百度终端适配代码优化设计三年级下册数学答案
  • 企业网站制作的书网络宣传
  • 建一个个人网站需要多少钱建站模板免费下载
  • 新材建设局网站手游推广平台哪个好
  • 网站编辑seo推广网站怎么制作
  • 电子商务网站建设模板代码百度销售平台怎样联系
  • 创建购物网站多少钱网络营销的发展现状及趋势
  • 广东企业网站建设小程序拉新推广平台
  • 莱西做网站公司推广网站哪个好
  • 做宠物网站需要实现什么功能产品如何推广
  • 惠州品牌网站建设公司哪里有小程序模板
  • 企业网站开发实训报告长沙官网seo收费标准
  • 建立网站做淘客网店推广方案策划书
  • 做网站要多少回扣seo外包优化服务商
  • 网站简繁转换网站搜索引擎优化的方法
  • wechat登录入口网站性能优化
  • 手机端网站开发免费b站推广网站入口
  • 网站样式模板下载杭州排名优化公司
  • 中国最大的网站制作公司外链查询工具
  • 网站搭建公司排行榜全国人大常委会副委员长
  • 世界互联网峰会概念股广东seo价格是多少钱
  • 以下软件中用来制作网页的有现在学seo课程多少钱
  • 平时发现同学做的ppt找的材料图片不错_不知道从哪些网站可以获得seo搜索引擎优化薪资水平
  • 网站商品展示页怎么做seo外链工具
  • 网站开发是哪个大概需要多少钱
  • 有人利用婚恋网站做微商百度关键词收录
  • 广州市11个区地图seo网络推广专员
  • 做推广网站需要商标吗东莞网站快速排名提升
  • 沈阳网站制作系统seo网站推广免费