传送门 题意:给一颗树,每个节点有个初始值,要求支持将i节点的值改为x或询问i节点到j节点的路径上有多少个值为x的节点. 思路: 考虑对每种颜色动态开点,然后用树剖+线段树维护就完了. 代码: #include<bits/stdc++.h> #define ri register int using namespace std; inline int read(){ int ans=0; char ch=getchar(); while(!isdigit(ch))ch=getchar(); w
题目链接:D. Frets On Fire 思路:明明可以离散化+二分写,思路硬是歪到了线段树上,自闭了,真实弟弟,怪不得其他人过得那么快 只和查询的区间长度有关系,排完序如果相邻的两个点的差值小于等于查询的区间长度,那么给结果带来的变化就会新增差值个数,如果大于区间长度那么就会新增区间长度个数 维护的话,线段树和二分都可以,二分需要离散化处理,再给差值排个序,每次找到第一个大于当前区间长度的差值位置就好了,(没实现,但是理论上应该没问题) 线段树直接动态开点可以不用离散化.. 实现代码: #i
C. Object-Oriented Programming time limit per test 3.0 s memory limit per test 1024 MB input standard input output standard output Functions overriding, is a well-known concept, when we are using inheritance in Object-Oriented Programming (OOP). For
题意 题目链接 Sol 树链剖分板子 + 动态开节点线段树板子 #include<bits/stdc++.h> #define Pair pair<int, int> #define MP(x, y) make_pair(x, y) #define fi first #define se second //#define int long long #define LL long long #define Fin(x) {freopen(#x".in",&quo
Do you like painting? Little D doesn't like painting, especially messy color paintings. Now Little B is painting. To prevent him from drawing messy painting, Little D asks you to write a program to maintain following operations. The specific format o