题目链接:传送门 题目: E. Vasya and a Tree time limit per test seconds memory limit per test megabytes input standard input output standard output Vasya has a tree consisting of n vertices with root . At first all vertices has written on it. Let d(i,j) be the…
Vasya and a Tree 题意: 给定一棵树,对树有3e5的操作,每次操作为,把树上某个节点的不超过d的子节点都加上值x; 思路: 多开一个vector记录每个点上的操作.dfs这颗树,同时以深度开一个树状数组,踩到u节点的时候,给数组add(deep, x); add(min(maxn,deep + op[u][i].fi + 1), - op[u][i].se); 搜索下去,反回前得到这个节点的答案,并消去这个点的影响. //#pragma GCC optimize(3) //#pr…
CodeForces - 1076E Problem Description: Vasya has a tree consisting of n vertices with root in vertex 1. At first all vertices has 0 written on it. Let d(i,j) be the distance between vertices i and j, i.e. number of edges in the shortest path from i…
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int N=2000000+9; int C[N],flower[N],pre[N],head[N]; int A[N],l[N],r[N],ans[N]; int cmp(int i,int j){ return r[i]<r[j]; } int lowbit(int t){ return t&…
Description 给定N个仅有a~z组成的字符串ai,每个字符串都有一个权值vi,有M次操作,操作分三种: Cv x v':把第x个字符串的权值修改为v' Cs x a':把第x个字符串修改成a' Q:求出当前的最大权字符串集合,使得这个集合中的字符串经过重新排列后满足除最后一个字符串外,前一个字符 串是后一个的前缀(两个字符串相同也是前缀关系,也可以一个字符串都不选) 前50%的数据可以接受离线算法,后50%的数据要求在线算法. Input 输入的第一行包含一个正整数Test表示当前的数…
I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个点,初始时候每个点权值都为0,m次修改,对v的叶子节点且距离小于d的都加上x 也就是v以下d层包括v自身都加上x 问最后每个点的权值 现在一想 用线段树来维护就是很自然的事了 但是要维护什么值呢 维护的就是某个深度上增加的值 先更新 后回溯取消更新 详见代码注释 #include <cstdio>…
Vasya has a tree consisting of n n vertices with root in vertex 1 1 . At first all vertices has 0 0 written on it. Let d(i,j) d(i,j) be the distance between vertices i i and j j , i.e. number of edges in the shortest path from i i to j j . Also, let'…
题面 Vasya has a tree consisting of n vertices with root in vertex 1. At first all vertices has 0 written on it. Let d(i,j) be the distance between vertices i and j, i.e. number of edges in the shortest path from i to j. Also, let's denote k-subtree of…
E - Vasya and a Tree 思路: dfs动态维护关于深度树状数组 返回时将当前节点的所有操作删除就能保证每次访问这个节点时只进行过根节点到当前节点这条路径上的操作 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #de…
题目描述 输入 第一行有三个整数N.M和R,分别表示树的节点数.指令和询问总数,以及X国的据点. 接下来N-1行,每行两个整数X和Y,表示Katharon国的一条道路. 接下来M行,每行描述一个指令或询问,格式见题目描述. 输出 对于每个询问操作,输出所求的值. 样例输入 5 8 1 1 2 2 3 3 4 4 5 Sum 2 4 Increase 3 5 3 Minor 1 4 Sum 4 5 Invert 1 3 Major 1 2 Increase 1 5 2 Sum 1 5 样例输出 0…