H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally tired of computing the length of the longest Fibonacci-ish sequence. He now plays around with more complex things such as Fibonacci-ish potentials. Fibo…
[CF633H]Fibonacci-ish II 题意:给你一个长度为n的序列$a_i$.m个询问,每个询问形如l,r:将[l,r]中的所有$a_i$排序并去重,设得到的新数列为$b_i$,求$b_1F_1+b_2F_2+...$($F_i$是斐波那契数). $n,m\le 30000,a_i\le 10^9$ 题解:比较好想,但细节很难处理的题(我根本不懂斐波那契数列~). 显然只能用莫队.我们对权值开一棵线段树,那么新加入一个数时,我们要进行的是:单点修改,区间整体换成下一个斐波那契数.如果…
温馨提示:本题十分卡常数,我手动开O2才过的.而数据范围不伦不类的n<=30000,常数小的O(n2)居然比O(n√nlogn)跑得快…… 考虑插进去一个元素对答案产生的影响.原本数列为Σa[i]f[i],其中1<=i<=n,然后考虑在k位置插入a[0],答案显然是a[1]f[1]+a[2]f[2]+...+a[0]f[k]+a[k]f[k+1]+...+a[n]f[n+1],然后直接区间加斐波那契数显然是不可能的.这时候要向后转移斐波那契数列,(a,b)->(a+b,a)->…
暴力 A - Ebony and Ivory import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner (new BufferedInputStream (System.in)); int a = cin.nextInt (); int b = cin.nextInt (); int c = cin.nex…
题目链接:http://codeforces.com/problemset/problem/633/G 大意是一棵树两种操作,第一种是某一节点子树所有值+v,第二种问子树中节点模m出现了多少种m以内的质数. 第一种操作非常熟悉了,把每个节点dfs过程中的pre和post做出来,对序列做线段树.维护取模也不是问题.第二种操作,可以利用bitset记录质数出现情况.所以整个线段树需要维护bitset的信息. 对于某一个bitset x,如果子树所有值需要加y,则x=(x<<y)|(x>>…
链接:https://ac.nowcoder.com/acm/contest/392/H 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld 题目描述 华华看书了解到,一起玩养成类的游戏有助于两人培养感情.所以他决定和月月一起种一棵树.因为华华现在也是信息学高手了,所以他们种的树是信息学意义下的. 华华和月月一起维护了一棵动态有根树,每个点有一个权值.刚开存档的时候,树上只有 0 号节点…
Codeforces 题目传送门 & 洛谷题目传送门 你可能会疑惑我为什么要写 *2400 的题的题解 首先一个很明显的想法是,看到斐波那契数列和 \(10^9+9\) 就想到通项公式,\(F_i=\dfrac{1}{\sqrt{5}}((\dfrac{1+\sqrt{5}}{2})^n-(\dfrac{1-\sqrt{5}}{2})^n)\).并且 \(5\) 在模 \(10^9+9\) 意义下的二次剩余存在,为 \(383008016\). 我们建两棵线段树分别维护展开式中 \((\dfra…
D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if th…
D. Fibonacci-ish 题目连接: http://www.codeforces.com/contest/633/problem/D Description Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if the sequence consists of at least two elements…
题目链接:http://codeforces.com/problemset/problem/633/C 大意就是给个字典和一个字符串,求一个用字典中的单词恰好构成字符串的匹配. 比赛的时候是用AC自动机写的,就是对于trie中每一个节点,判断是否为终结点,以及当前字符所在位置p减去trie中这个节点的深度也即某一单词的长度l,判断dp[p-l]是否可以被构成,可以的话直接break并且标记当前dp值. 赛后想了想,其实直接一个trie就行了,每个单词才1000的长度,又想起来我去年给人讲过类似的…