[USACO17JAN]Promotion Counting】的更多相关文章

Luogu3605 [USACO17JAN]Promotion Counting晋升者计数 给一棵 \(n\) 个点的树,点 \(i\) 有一个权值 \(a_i\) .对于每个 \(i\) ,求 \(\displaystyle\sum_{j\in subtree(i)}{[a_i<a_j]}\) \(n\leq10^5,\ fa_i<i\) 树状数组 树上逆序对?一眼线段树合并...空间没毛病.. 回想求序列逆序对的过程,发现在树上做时只需减去树状数组中以往的贡献,于是便可以愉快地树状数组搞了…
题面:P3605 [USACO17JAN]Promotion Counting晋升者计数 题解:这是一道万能题,树状数组 || 主席树 || 线段树合并 || 莫队套分块 || 线段树 都可以写..记得离散化 线段树合并版: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; ; ,edge_head[maxn],W[ma…
P3605 [USACO17JAN]Promotion Counting晋升者计数 题目描述 奶牛们又一次试图创建一家创业公司,还是没有从过去的经验中吸取教训--牛是可怕的管理者! 为了方便,把奶牛从 1 \(\cdots\) N(1 \(\leq\) N \(\leq\) 100, 000) 编号,把公司组织成一棵树,1 号奶牛作为总裁(这棵树的根节点).除了总裁以外的每头奶牛都有一个单独的上司(它在树上的 "双亲结点").所有的第 i 头牛都有一个不同的能力指数 p(i),描述了她…
题目传送门 Promotion Counting 题目描述 The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers! The cows, conveniently numbered 1 \ldots N1…N (1 \leq N \leq 100,0001≤N≤100,000), organ…
题目描述 奶牛们又一次试图创建一家创业公司,还是没有从过去的经验中吸取教训--牛是可怕的管理者! 为了方便,把奶牛从 1 \cdots N(1 \leq N \leq 100, 000)1⋯N(1≤N≤100,000) 编号,把公司组织成一棵树,1 号奶牛作为总裁(这棵树的根节点).除了总裁以外的每头奶牛都有一个单独的上司(它在树上的 “双亲结点”).所有的第 ii 头牛都有一个不同的能力指数 p(i)p(i),描述了她对其工作的擅长程度.如果奶牛 ii 是奶牛 jj 的祖先节点(例如,上司的上…
题目链接 luogu 思路 可以说是线段树合并的练手题目吧 也没啥说的,就是dfs,然后合并... 看代码吧 错误 和写主席树错的差不多 都是变量写错.... 代码 #include <bits/stdc++.h> #define FOR(i,a,b) for(int i=a;i<=b;++i) using namespace std; const int maxn=1e5+7; inline int read() { int x=0,f=1;char s=getchar(); for(…
思路 线段树合并的板子.. 和子节点合并之后在值域线段树上查询即可 代码 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int MAXN = 1000100; int n,Nodecnt,root[MAXN],u[MAXN<<1],v[MAXN<<1],cnt,fir[MAXN],nxt[MAXN<<1],ans…
Description The cows have once again tried to form a startup company, failing to remember from past experience t hat cows make terrible managers!The cows, conveniently numbered 1…N1…N (1≤N≤100,000), organize t he company as a tree, with cow 1 as the…
题目大意:给你一棵树,求以某节点为根的子树中,权值大于该节点权值的节点数 本题考查dfs的性质 离散+树状数组求逆序对 先离散 我们发现,求逆序对时,某节点的兄弟节点会干扰答案 所以,我们在递推时统计一次答案,递归时再统计一次答案,两者的差值就是最终结果 #include <bits/stdc++.h> #define dd double #define N 100100 using namespace std; int n,cnt,ma,lst; int a[N],head[N],s[N],…
线段树合并. 正解好像不是线段树合并,但是出于练手的目的写了线段树合并. 大概就是对于左右子树,如果有一个为空,返回非空的,如果都不为空,就把这两个整合到一起就行了. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; const int N=100005; int tot,ls[N<<5],rs[N&…
这道题开10倍左右一直MLE+RE,然后尝试着开了20倍就A了...窒息 对于这道题目,我们考虑使用线段树合并来做. 所谓线段树合并,就是把结构相同的线段树上的节点的信息合在一起,合并的方式比较类似左偏树什么的. 我们对于每个节点用权值线段树查询大于它的子节点数量,然后把当前节点并到它的父亲上面去. 对于此类型的题目我们通常使用动态开点的线段树(不然炸的没边). 时间复杂度应该是$O(nlogn)$ AC代码如下: 455ms 32824kb #include <bits/stdc++.h>…
题目描述 The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers! The cows, conveniently numbered $1 \ldots N\left( 1\leq N\leq 100,000\right)$ organize the company as a tree, wi…
前言 巨佬说:要有线段树,结果蒟蒻打了一棵树状数组... 想想啊,奶牛都开公司当老板了,我还在这里码代码,太失败了. 话说奶牛开个公司老板不应该是FarmerJohn吗? 题解 刚看到这道题的时候竟然没有想到深搜,然后仔细一想,发现果然要用深搜. 但是这个树形结构怎么维护是一个问题?难道打个欧拉序... 其实做法非常简单,首先按照套路我们把牛的能力值离散化(由于没有相同的值,所以这个离散化非常简单). 然后重点来了,建立一个维护某一能力值牛的个数的树状数组. 我们深搜到一个点的时候,我们不希望计…
分块\(yyds\) ----关于线段树合并的题我用分块过掉这件事 题目传送门 先说正解 正解当然是线段树合并等一类做法了 至于解析...出门右转题解区第一篇 (就是他让我看不懂,然后用分块打的\(QAQ\)) 给出 fengwu 的\(code\) #include<bits/stdc++.h> #include<iostream> using namespace std; #define re register int const int N=100005; int n; in…
4756: [Usaco2017 Jan]Promotion Counting Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 305  Solved: 217[Submit][Status][Discuss] Description The cows have once again tried to form a startup company, failing to remember from past experience t hat cow…
[题解]晋升者计数 Promotion Counting [USACO 17 JAN] [P3605] 奶牛们又一次试图创建一家创业公司,还是没有从过去的经验中吸取教训.!牛是可怕的管理者! [题目描述] 奶牛从 \(1\) ~ \(N(1≤N≤1e5)\) 进行了编号,把公司组织成一棵树,\(1\)号奶牛作为总裁(树的根节点).除总裁以外的每头奶牛都有且仅有唯一的一个的上司(即它在树上的父结点).每一头牛\(i\)都有一个不同的能力指数 \(p(i)\),描述了她对其工作的擅长程度.如果奶牛…
题目描述 The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers! The cows, conveniently numbered  (), organize the company as a tree, with cow 1 as the president (the root of th…
(题面来自Luogu) 题目描述 奶牛们又一次试图创建一家创业公司,还是没有从过去的经验中吸取教训--牛是可怕的管理者! 为了方便,把奶牛从 1⋯N(1≤N≤100,000) 编号,把公司组织成一棵树,1 号奶牛作为总裁(这棵树的根节点).除了总裁以外的每头奶牛都有一个单独的上司(它在树上的 "双亲结点").所有的第 i 头牛都有一个不同的能力指数 p(i),描述了她对其工作的擅长程度.如果奶牛 i 是奶牛 j 的祖先节点(例如,上司的上司的上司),那么我们我们把奶牛 j 叫做 i 的…
Description The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers!The cows, conveniently numbered 1…N1…N (1≤N≤100,000), organize the company as a tree, with cow 1 as the pr…
题意 题目链接 Sol 线段树合并板子题 #include<bits/stdc++.h> using namespace std; const int MAXN = 400000, SS = MAXN * 21; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >=…
题目描述 The cows have once again tried to form a startup company, failing to remember from past experience t hat cows make terrible managers!The cows, conveniently numbered 1…N1…N (1≤N≤100,000), organize t he company as a tree, with cow 1 as the preside…
描述 The cows have once again tried to form a startup company, failing to remember from past experience t hat cows make terrible managers!The cows, conveniently numbered 1-N1-N (1≤N≤100,000), organize t he company as a tree, with cow 1 as the president…
Description n只奶牛构成了一个树形的公司,每个奶牛有一个能力值pi,1号奶牛为树根. 问对于每个奶牛来说,它的子树中有几个能力值比它大的. Input n,表示有几只奶牛 n<=100000 接下来n行为1-n号奶牛的能力值pi 接下来n-1行为2-n号奶牛的经理(树中的父亲) Output 共n行,每行输出奶牛i的下属中有几个能力值比i大 Sample Input 5 804289384 846930887 681692778 714636916 957747794 1 1 2 3…
[题意]带点权树,统计每个结点子树内点权比它大的结点数. [算法]线段树合并 [题解]对每个点建权值线段树(动态开点),DFS中将自身和儿子线段树合并后统计. 注意三个量tot,cnt,tots,细心查错. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ; int n,first[maxn],cnt,tot,tots,root[maxn],a[maxn],b[max…
Description The cows have once again tried to form a startup company, failing to remember from past experience t hat cows make terrible managers!The cows, conveniently numbered 1…N1…N (1≤N≤100,000), organize t he company as a tree, with cow 1 as the…
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4756 [题目大意] 给出一棵树,对于每个节点,求其子树中比父节点大的点个数 [题解] 我们考虑每个权值建立一棵线段树,边dfs边将子节点合并为一颗线段树, 那么只要查询当前点的树上后缀和即可. [代码] #include <cstdio> #include <algorithm> #include <cstring> #include <vector&…
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4756 [题解] dsu on tree,树状数组直接上 O(nlog^2n) # include <vector> # include <stdio.h> # include <string.h> # include <iostream> # include <algorithm> // # include <bits/stdc++.…
原文地址:http://www.cnblogs.com/GXZlegend/p/6832263.html 题目描述 The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers!The cows, conveniently numbered 1…N1…N (1≤N≤100,000), organi…
题目翻译: zxyer来到了一个神奇的公司工作,之所以神奇,是因为这个公司的员工的职位并不与他们的水平相称,有的职位极低的职员的经验非常丰富,而有些经理甚至老板都是个萌新.有一天,zxyer收到了老板打来的电话,要求他安排一下让所有员工包括老板本人都去向下层员工学习一下工作经验.可是机智的zxyer很快就明白一件事情,显然不能安排一个员工到他的上司那儿学习经验,这样会太尴尬,同样就更不可能到上司的上司那儿去啦!所以只能安排一个员工到比它职位低的,且属于他管的员工那儿去学习经验. 并且,一个员工能…
浅谈线段树合并:https://www.cnblogs.com/AKMer/p/10251001.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?id=4756 对于每个结点用一棵值域线段树维护子树内结点的信息,然后该查询查询该合并合并就好了. 时间复杂度:\(O(nlogn)\) 空间复杂度:\(O(nlogn)\) 代码如下: #include <cstdio> #include <algorithm> using na…