Description 有一个长为\(n\)的数列\(a_{1},a_{2}...a_{n}\),你需要对这个数列维护如下两种操作: \(1\space l \space r\space x\) 表示将数列中的\(a_{l},a_{l+1}...a_{r-1},a_{r}\)加上\(x\) \(2\space l\space r\) 表示要你求出\(\sum_{i=l}^{r}fib(a_{i})\)对\(10^9+7\)取模后的结果 fib(x)fib(x)表示的是斐波那契的第\(x\)项,\…
E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains…
传送门 大意: 给定n节点树, 求划分为不超过$k$个连通块的方案数. n,k<=300. 核心观察是每个连通块深度最低的点固定以后染色方案就固定了. 所以答案为$\sum\limits_{i=1}^k\binom{k}{i}i!\binom{n-1}{i-1}$…
E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from…
一.线段树 线段树既是线段也是树,并且是一棵二叉树,每个结点是一条线段,每条线段的左右儿子线段分别是该线段的左半和右半区间,递归定义之后就是一棵线段树. 例题:给定N条线段,{[2, 5], [4, 6], [0, 7]}, M个点{2, 4, 7},判断每个点分别在几条线段出现过? 1.构建线段树 2.处理线段 三条线段分割之后 3.查询 对于每一个值我们就可以开始遍历这一颗线段树,加上对于结点的count字段便是在线段中出现的次数 比如对于4,首先遍历[0, 7],次数 = 0+1=1:4在…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5877 题意:给一棵树和各点的权值a,求点对(u,v)个数,满足:1.u是v的祖先,2.a(u)*a(v)<=k. 对于这棵树,我们先存好树的结构.再离散化,最后dfs的时候往线段树里插点,那对应idx的值就是1.然后二分找不大于k/a[v]的下标,线段树统计计数就行了.换儿子的时候记得抹去上一个兄弟. #include <bits/stdc++.h> using namespace std;…
Pog and Szh are playing games. Firstly Pog draw a tree on the paper. Here we define 1 as the root of the tree.Then Szh choose some nodes from the tree. He wants Pog helps to find the least common ancestor (LCA) of these node.The question is too diffi…
[Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\(\sum_{i=l}^r a_i(i-l+1)^k \mod 10^9+7\) \(n,m \leq 10^5,k \leq 5\) 分析 根据二项式定理 \[(i-l+1)^k=\sum_{j=0}^k (-1)^{k-j} C_{k}^j i^j(l-1)^{k-j}\] 那么 \(\begi…
比赛时,第二题就是做的这个,当时果断没仔细考虑,直接用线段树暴力求.结果易想而知,超时了. 比赛后搜了搜题解,恍然大悟. 思路:显然用线段树,但是由于每次查询都会有变,所以不可能存储题目中的式子.   这里要注意:k的值非常小,所以应该是将式子按二项式定理展开   (i-L+1)^k=(i+(1-L))^k   展开之后可以发现:我们可以在节点存储ai*i,ai*i^2,ai*i^3,ai*i^4,ai*i^5 (L<=i<=R)的累加和.   至于关于(1-L)^j(j=0~5)可以预先枚举…
题目链接: http://codeforces.com/problemset/problem/558/E E. A Simple Task time limit per test5 secondsmemory limit per test512 megabytes 问题描述 This task is very simple. Given a string S of length n and q queries each query is on the format i j k which mea…