CF B. Gardener and the Array】的更多相关文章

比赛时,第二题就是做的这个,当时果断没仔细考虑,直接用线段树暴力求.结果易想而知,超时了. 比赛后搜了搜题解,恍然大悟. 思路:显然用线段树,但是由于每次查询都会有变,所以不可能存储题目中的式子.   这里要注意: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)可以预先枚举…
传送门 题意:    有m个区间,n个a[ i ] , 选择若干个区间,使得整个数组中的最大值和最小值的差值最小.n<=1e5,m<=300; 思路: 可以知道每个i,如果一个区间包含这个点,就让这个区间发挥作用.枚举每个i,找到最大值即可. 当然这个复杂度不对,我们可以通过线段树保存数组的最大值和最小值,每次区间在左端点发挥作用,在右端点去掉作用. #include <algorithm> #include <iterator> #include <iostre…
vjudge上莫队专题 真的是要吐槽自己(自己的莫队手残写了2个bug) s=sqrt(n) 是元素的个数而不是询问的个数(之所以是sqrt(n)使得左端点每个块左端点的范围嘴都是sqrt(n)) 在重载<是将q[i].l/s<q2[i].l/s 写成q1[i].l<s<q2[i].l<s 导致一下午都在调bug疯了 Sona 比小Z的袜子简单,直接维护区间频度的^3 需要离散化(离散化化的标号应提前准备好,如果用时在二分查找会增加复杂度) 还有比较坑的一点是多case,但样…
BeanFactory和ApplicationContext的区别 ApplicationContext 方式加载:创建容器的同时 容器初始化,容器所有的bean创建完毕   Spring容器中获取一个对象 通过类型直接获取 BeanFactory 方式加载:创建容器对象,BeanFactory当调用getBean获取响应对象是才创建对象 Spring容器中获取一个对象 通过类型直接获取 这两个区别是一个容器加载的时候实例化对象,一个是在使用的时候才实例化对象. 静态工厂注入: 1.创建静态工厂…
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:1 second     memory limit per test:256 megabytes Description Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interes…
B. Yet Another Array Partitioning Task time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output An array bb is called to be a subarray of aa if it forms a continuous subsequence of aa , that is, if…
C. Ayoub and Lost Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ayoub had an array aa of integers of size nn and this array had two interesting properties: All the integers in the a…
题解 非常容易想到的线段树, 还可以用并查集来. 还有一位大神用了$O(n)$ 就过了Orz 要判断是否能染色出输入给出的序列,必须满足两个条件: 1. 序列中必须存在一个$q$ 2. 两个相同的数$x$的中间不存在比 $ x$ 小的数 首先判断输入的数列中是否存在$q$, 若不存在$q$ 且没有 $a_i = 0$, 表示序列中一定没有$q$, 直接输出NO 若存在某个$a_i = 0$ , 将任意一个染成$q$即可 然后我们再查询两个相同的数$x$ 中是否存在比$x$ 小的数,用线段树来维护…
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integer…
任意门:http://codeforces.com/contest/1114/problem/B B. Yet Another Array Partitioning Task time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output An array bb is called to be a subarray of aa if it f…