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…
题目链接 Powerful array 给你n个数,m次询问,Ks为区间内s的数目,求区间[L,R]之间所有Ks*Ks*s的和. $1<=n,m<=200000,   1<=s<=10^{6}$ 考虑莫队算法 把区间排序,然后让l和r分别询问即可. 根据排序的方式,l指针和r指针移动次数和大概是$n\sqrt{n}$ 级别的. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (…
和BZOJ2038差不多..复习一下. #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int block; struct Query{ int i,l,r; bool operator<(const Query &q)const{ if(l/block==q.l/block) return r<q.r; return l/block<q.l/b…
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 …
题目描述: Problem Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≤ l ≤ r ≤ n. For every positive integer s denote by Ks the number of occurrences of s into the subarra…
题目传送门 题目描述 小B有一个序列,包含$N$个$1~K$之间的整数.他一共有$M$个询问,每个询问给定一个区间$[L...R]$,求$\sum \limits_{i=1}^{K}c(i)^2$的值,其中$c(i)$表示数字$i$在$[L...R]$中的重复次数.小$B$请你帮助他回答询问. 输入格式 第一行,三个整数N,M,K.第二行,N个整数,表示小B的序列.接下来的M行,每行两个整数L,R. 输出格式 M行,每行一个整数,其中第i行的整数表示第i个询问的答案. 样例 样例输入 6 4 3…
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 …
胡小兔的良心莫队教程:莫队.带修改莫队.树上莫队   在开始学习莫队之前,照例先甩一道例题:BZOJ 1878 HH的项链. 题意:求区间内数的个数,相同的数只算一次. 在我关于这道题的上一篇题解中,我使用了主席树来在线做这道题:在洛谷的一道类似题中,我使用了分块:而如果不要求在线,这道题还有一种极其好写的方法——莫队. 什么是莫队? 莫队不是一种叫做莫的队列(我第一次听到这个名字时竟然是这么理解的 -_-|||),它是以发明人前国家队队长莫涛——“莫队”的名字命名的. 它是一种传说中“能解决一…
传送门 题意 给出n个数,m次访问,每次询问[L,R]的数有多少种排列 分析 \(n,m<=30000\),我们采用莫队算法,关键在于区间如何\(O(1)\)转移,由排列组合知识得到,如果加入一个数,\(区间值*区间长度/该数出现次数\),减去一个数则相反操作讲解 trick 1.我的原先莫队写法不能ac,原因是我传入的L,R是全局变量,在insert和erase前就++,--了,而没有达到预期目的,把R++,L--分离即可 代码 //wa #include <bits/stdc++.h>…
莫队算法就是优化的暴力算法.莫队算法是要把询问先按左端点属于的块排序,再按右端点排序.只是预先知道了所有的询问.可以合理的组织计算每个询问的顺序以此来降低复杂度. D. Powerful array 典型的莫队算法题 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <string&g…