CF86D Powerful array】的更多相关文章

题意翻译 题意:给出一个n个数组成的数列a,有t次询问,每次询问为一个[l,r]的区间,求区间内每种数字出现次数的平方×数字的值 的和. 输入:第一行2个正整数n,t. 接下来一行n个正整数,表示数列a1​~an的值. 接下来t行,每行两个正整数l,r,为一次询问. 输出:t行,分别为每次询问的答案. 数据范围:1≤n,t≤2∗105,1≤ai≤106,1≤l,r≤n 题目描述 An array of positive integers a1,a2,...,an a_{1},a_{2},...,…
原题传送门 裸的莫队啊,我博客里有对莫队较详细的介绍 这道题很简单,可以说是裸的模板 但是如何在已有的值上进行操作? 小学生应该都知道 那么转移就超级简单了qaq inline void add(register int c) { sum+=(num[c]+num[c]+1)*c; ++num[c]; } inline void del(register int c) { --num[c]; sum-=(num[c]+num[c]+1)*c; } 要开long long(虽说我没试过int,但我…
D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 …
莫队算法就是优化的暴力算法.莫队算法是要把询问先按左端点属于的块排序,再按右端点排序.只是预先知道了所有的询问.可以合理的组织计算每个询问的顺序以此来降低复杂度. D. Powerful array 典型的莫队算法题 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <string&g…
codefroce D. Powerful array[初识块状数组] 由于是初始所以,仅仅能先用别人的分析.囧... 题目: 给定一个数列:A1, A2,--,An,定义Ks为区间(l,r)中s出现的次数. t个查询,每一个查询l,r,对区间内全部a[i],求sigma(K^2*a[i]) 离线+分块 将n个数分成sqrt(n)块. 对全部询问进行排序,排序标准: 1. Q[i].left /block_size < Q[j].left / block_size (块号优先排序) 2. 假设1…
D. Powerful array 题意 给定一个数列:a[i] (1<= i <= n) K[j]表示 在区间 [l,r]中j出现的次数.有t个查询,每个查询l,r,对区间内所有a[i],求sigma(K[a[i]] * K[a[i]] * a[i]). 分析 首先将区间分块,每块sqrt(n)个,先读入所有的查询,对查询进行排序:先按块序号从小到大,再按右端点的值从小大到排序. 按顺序读入查询,动态变更区间,以及区间的值.如果某个点出现了 x 次,出现 x + 1 次时,区间内增加(2 *…
题目链接:点击传送 D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar…
D. Powerful array time limit per test seconds memory limit per test megabytes input standard input output standard output An array of positive integers a1, a2, ..., an ..., ar,  ≤ l ≤ r ≤ n. For every positive integer s denote by Ks the number of occ…
题目链接: D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, wh…
题目链接:http://codeforces.com/problemset/problem/86/D D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive integers a1, a2, ..., an is given. Let us consider…