CF #271 F Ant colony 树】的更多相关文章

题目链接:http://codeforces.com/contest/474/problem/F 一个数组,每一次询问一个区间中有多少个数字可以整除其他所有区间内的数字. 能够整除其他所有数字的数一定是这些数字的gcd,所以可以用一个线段树来查询区间gcd. 接着需要统计区间内这个数字的出现个数,在读取数组时,顺便保存一个pair<int,int>键为数字,val为位置的数组,再sort一下,统计区间内某个数字出现次数,直接upper_bound-lower_bound即可. #include…
区间重复不会影响GCD,ST表当然是支持的啦,常数这么小. 学到了三个东西: 1.lower_bound返回的是大于等于的位置,要判是否不存在(end())和是否超出所求[x,y]范围. 2.ST表更新时存在一个i+(1<<j-1)的下标,存在极大越界隐患,以前数组开的大就无所谓,讲道理边界是要判的. 3.及时存代码,又蓝屏了qwq #include<iostream> #include<cstdio> #include<vector> #include&l…
F. Ant colony time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si…
线段树求某一段的GCD..... F. Ant colony time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n)…
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数就是答案. 要是符合条件的话,那这个数的大小一定是等于gcd(a[l]...a[r]). 我们求区间gcd的话,既可以利用线段树性质区间递归下去然后返回求解,但是每次查询是log的,所以还可以用RMQ,查询就变成O(1)了. 然后求解区间内有多少个数的大小等于gcd的话,也是利用线段树的性质,区间递…
题目描述: F. Ant colonytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si.…
[BZOJ3872][Poi2014]Ant colony 试题描述 There is an entrance to the ant hill in every chamber with only one corridor leading into (or out of) it. At each entry, there are g groups of m1,m2,...,mg ants respectively. These groups will enter the ant hill one…
3872: [Poi2014]Ant colony Time Limit: 30 Sec  Memory Limit: 128 MB Description   There is an entrance to the ant hill in every chamber with only one corridor leading into (or out of) it. At each entry, there are g groups of m1,m2,...,mg ants respecti…
[BZOJ3872][Poi2014]Ant colony Description 给定一棵有n个节点的树.在每个叶子节点,有g群蚂蚁要从外面进来,其中第i群有m[i]只蚂蚁.这些蚂蚁会相继进入树中,而且要保证每一时刻每个节点最多只有一群蚂蚁.这些蚂蚁会按以下方式前进: ·在即将离开某个度数为d+1的点时,该群蚂蚁有d个方向还没有走过,这群蚂蚁就会分裂成d群,每群数量都相等.如果d=0,那么蚂蚁会离开这棵树. ·如果蚂蚁不能等分,那么蚂蚁之间会互相吞噬,直到可以等分为止,即一群蚂蚁有m只,要分成…
[BZOJ3872]Ant colony(二分,动态规划) 题面 又是权限题... Description There is an entrance to the ant hill in every chamber with only one corridor leading into (or out of) it. At each entry, there are g groups of m1,m2,...,mg ants respectively. These groups will ent…