CF587F Duff is Mad】的更多相关文章

题意 给你 \(n\) 个串 \(s_{1\cdots n}\) ,每次询问给出 \(l,r,k\) ,问在 \(s_{l\cdots r}\) 中出现了多少次 \(s_k\) . \(n,q,\sum|s|\le 10^5\) 分析 先建AC自动机的 \(fail\) 树, 我们考虑两种暴力: 将 \(l​\) 到 \(r​\) 中的每个串的末尾节点子树标记,查询 \(s_k​\) 的所有节点 \(fail​\) 树到根的路径和. 将 \(s_k\) 的每个节点的子树标记,查询 \(l\) 到…
题目 有趣的思想 首先暴力的话,自然是对每一个询问在\(AC\)自动机上跑一遍\(k\),看看跑出来的节点在\(fail\)树到根的路径上有多少个\(l\)到\(r\)之间的结束标记就好了 我们发现无论怎么优化好像都不是很可行,考虑一下对根号优化 对于长度大于\(\sqrt{n}\)的串,显然这样的串也不会超过\(\sqrt{n}\)个,我们把这些串在\(AC\)机上跑一遍,之后统计一下子树和,统计一个前缀和就可以回答询问了 这样复杂度是\(O(n\sqrt{n})\) 对于长度小于\(\sqr…
考虑两一个暴力 1 因为询问\([a,b]\)可以拆成\([1,b]\)-\([1,a-1]\)所以把询问离线,然后就是求\([1,x]\)中被\(S_i\)包含的串的数量.考虑当\([1,x-1]->[1,x]\)时我们把\(S_x\)结束节点在fail树的子树加1.然后询问就是求\(S_i\)在AC自动机上跑时经过所有点的点权用树状数组维护.设\(\sum{len[S_i]}=L\)这样的复杂度就是\(O(mLlogL)\)无法通过此题. 2 依然离线.这次我们把\(S_i\)放在fail树…
[CF587F]Duff is Mad 题意:给出n个串$s_1,s_2..s_n$,有q组询问,每次给出l,r,k,问你编号在[l,r]中的所有串在$s_k$中出现了多少次. $\sum|s_i|,q\le 10^5$ 题解:先将询问离线,改成前缀相减.然后建出AC自动机,考虑分块. 对于长度$>\sqrt n$的询问串,这种串最多$\sqrt n$个,我们每次可以扫一遍整个fail树,处理出每个节点到根的路径上有多少个询问串中的点.然后将所有串一个一个加入到fail树里,假如加入的串的结束节…
题面传送门 第一眼看成了 CF547E-- 话说 CF587F 和 CF547E 出题人一样欸--还有另一道 AC 自动机的题 CF696D 也是这位名叫 PrinceOfPersia 的出题人出的--似乎这位神仙很擅长字符串? 跑题了跑题了-- 令 \(m=\sum|s_i|\) u1s1 我做这题的时候一直在考虑按照 CF547E 的套路对询问进行差分处理,然鹅并没有什么卵用.因为这题相当于每次加入一个字符串时将这个字符串结尾位置 fail 树的子树中的所有节点访问次数 \(+1\),并询问…
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取模. 因为取模后至少减半, 复杂度$O(nlognlogC)$ 2. CF 431E Chemistry Experiment 大意: n个试管, 第$i$个试管有$a_i$单位水银, m个操作: 1, 修改$a_x$改为$v$. 2, 将$v$单位水倒入试管, 求一种方案使得有水的试管水银与水总量的最大…
A.Duff and Weight Lifting(思维) 显然题目中只有一种情况可以合并 2^a+2^a=2^(a+1).我们把给出的mi排序一下,模拟合并操作即可. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <sta…
Text Aeroplanes are slowly driving me mad. I live near an airport and passing planes can be heard night and day. The airport was built years ago, but for some reason it could not be used then. Last year, however, it came into use. Over a hundred peop…
B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, …
在看strcpy.memcpy等的实现发现用了内存对齐,每一个word拷贝一次的办法大大提高了实现效率,参加该blog(http://totoxian.iteye.com/blog/1220273). duff's device也是利用了类似的原理减少比较的次数来提高了效率. 前几天在网上看见了一段代码,叫做“Duff's Device”,后经验证它曾出现在Bjarne的TC++PL里面: void send( int * to, int * from, int count)         …
这里 irf 两个交换机 S4 S5 S4 S4的MEmber id 为1 IRF member 1 renumber 1 S4的 irf 优先为10 irf member priority 10 链形堆叠 irf domain 10 进入 要irf的端口 int range name irf int ten-g 1/0/50 to ten-g1/0/51 暂时关闭 shutdown 进入irf port irf-port 1/1 port group int ten-g 1/0/50 port…
//   B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive int…
题意: Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件. 思路: 只要判断相邻两天中,今天的总花费 = ai*pi 与昨天的总花费(还有加上今天要吃的肉的重量)= (ai-1 + ai)*pi-1 . 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <fstream>…
C. Duff in the Army Recently Duff has been a soldier in the army. Malek is her commander. Their country, Andarz Gu has n cities (numbered from 1 to n) and n - 1 bidirectional roads. Each road connects two different cities. There exist a unique path b…
D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/D Description While Duff was resting in the beach, she accidentally found a strange array b0, b1, ..., bl - 1 consisting of l positive integers. Th…
C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/C Description Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of wei…
B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/B Description Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such…
A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/A Description Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly aikilo…
1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Mob was hijacked by the mayor of the Town "TruthTown". Mayor wants Mob to count the total population of the town. Now the naive approach to this p…
主要是下面的代码: register n = (count + 7) / 8;   /\* count > 0 assumed \*/ switch (count % 8) { case 0:    do { \*to = \*from++; case 7:     \*to = \*from++; case 6:     \*to = \*from++; case 5:     \*to = \*from++; case 4:     \*to = \*from++; case 3:    …
Tom Duff首先在C语言中提出了展开循环的构想,所以这种模式被称之为Duff策略.Duff策略背后的思想是每一次循环完成标准循环的1-8次.首先通过数组值得总数除以8来取定循环次数.Duff发现对于这个处理过程来说,8是最佳数值(不是任意值).由于并非所有数组的长度都能被8整除,所以你必须通过取余运算计算出有多少项不被额外处理.实现如下: var arrays = ['Z', 'Y', 'X', 'W', 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O', 'N'…
猜想:Duff装置再循环里面,直接调用的方法越多(也就是case的数量比较多),性能相对越好 ???!!! 我们基于Duff装置来做进一步的测试. 然后分别添加两个新的函数,一个函数式 case有4种情况,另一个是case有 12种情况... function duffDevice() { var testVal = 0; var n = Math.ceil(iterations / 8); var caseTest = iterations % 8; do { switch (caseTest…
简介: 本文主要介绍几种基于灰度的图像匹配算法:平均绝对差算法(MAD).绝对误差和算法(SAD).误差平方和算法(SSD).平均误差平方和算法(MSD).归一化积相关算法(NCC).序贯相似性检测算法(SSDA).hadamard变换算法(SATD).下面依次对其进行讲解. MAD算法 介绍 平均绝对差算法(Mean Absolute Differences,简称MAD算法),它是Leese在1971年提出的一种匹配算法.是模式识别中常用方法,该算法的思想简单,具有较高的匹配精度,广泛用于图像…
Javascript 中会用到for 循环,当要循环的数据记录很多的时候,可能会对性能产生很大影响.这时我们可以考虑展开for循环,这时就要用到Duff装置(Duff Device). 先来看一个小例子,用for循环来实现: function regularFoorLoop() { var testVal = 0,i=0; for (i = 0; i <= iterations; i++) { testVal++; } } 这个for循环可以用duff 展开如下,(Jeff Greenberg…
1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Mob was hijacked by the mayor of the Town "TruthTown". Mayor wants Mob to count the total population of the town. Now the naive approach to this p…
B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer…
A. Duff and Meat time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exact…
一.IRF简介 IRF(Intelligent Resilient Framework,智能弹性架构)是H3C自主研发的软件虚拟化技术.它的核心思想是将多台设备通过IRF物理端口连接在一起,进行必要的配置后,虚拟化成一台“分布式设备”.使用这种虚拟化技术可以集合多台设备的硬件资源和软件处理能力,实现多台设备的协同工作.统一管理和不间断维护. 二.多IRF冲突检测(MAD功能) 2.1 机制介绍 IRF链路故障会导致一个IRF变成两个新的IRF.这两个IRF拥有相同的IP地址等三层配置,会引起地址…
一.组网需求 由于公司人员激增,接入层交换机提供的端口数目已经不能满足PC的接入需求.现需要在保护现有投资的基础上扩展端口接入数量,并要求网络易管理.易维护. 二.组网图 三.配置思路 Device A提供的接入端口数目已经不能满足网络需求,需要另外增加一台设备Device B.(本文以两台设备组成IRF为例,在实际组网中可以根据需要,将多台设备组成IRF,配置思路和配置步骤与本例类似) .鉴于第二代智能弹性架构IRF 技术具有管理简便.网络扩展能力强.可靠性高等优点,所以本例使用IRF技术构建…
一.组网需求 由于网络规模迅速扩大,当前中心交换机(Device A)转发能力已经不能满足需求,现需要在保护现有投资的基础上将网络转发能力提高一倍,并要求网络易管理.易维护. 二.组网图 三.配置思路 Device A处于局域网的汇聚层,为了将汇聚层的转发能力提高一倍,需要另外增加一台设备Device B.鉴于第二代智能弹性架构IRF技术具有管理简便.网络扩展能力强.可靠性高等优点,所以本例使用IRF技术构建网络汇聚层(即在Device A和Device B上配置IRF功能),接入层设备通过聚合…