Codeforces 1189F. Array Beauty】的更多相关文章

传送门 首先可以注意到序列里面元素的顺序对答案是没有影响的,所以二话不说先排序再看看怎么搞 考虑枚举每种子序列可能产生的贡献并算一下产生这个贡献的子序列有多少 考虑设 $F(x)$ 表示选择的元素差值至少为 $x$ 的长度为 $k$ 的子序列的方案数 那么最终如果直接把每个 $F(x),x \in [1,max(a)]$ 加起来会发现,对于任意一种差值为 $t$ 的方案,它都被所有 $x<=t$ 的 $F(x)$ 各计算到了一次,那么总贡献即为 $t$,所以只要求出 $F$ 然后加起来就是我们要…
Array Beauty 给出一个长度为n的序列\(\{a_i\}\),定义一个序列的权值为其中元素两两之差的绝对值的最小值,询问\(\{a_i\}\)长度为K的子序列的权值之和\(\% 998244353\),\(2\leq k\leq n\leq 1000,max(a_i)\leq 10^5\). 解 询问权值之和,除了枚举全部情况加起来,还有一种思路,对于每个权值看其出现的次数. 于是可以枚举权值,找规律容易知道一种方案对应权值最大上限为\(max(a_i)/(k-1)\),枚举权值i,因…
大意: 定义$n$元素序列$a$的美丽度为 $\min\limits_{1\le i<j\le n}|a_i-a_j|$. 给定序列$a$, 求$a$的所有长为$k$的子序列的美丽度之和. 记 长为$k$的相邻元素距离都$\ge x$的子序列个数 为$f(x)$. 那么答案就为$\sum\limits_{x=1}^{\frac{1e5}{k-1}} f(x)$. $f(x)$很容易可以$O(nk)$的$dp$求出, 总复杂度就为$O(1e5n)$. #include <iostream>…
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output a is an array of n positive integers, all of which are not greater than…
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between easy and hard versions is a number of elements in the array. You are given an array \(a\) consisting of \(n\) integers. The value of the \(i\)-th element…
http://codeforces.com/problemset/problem/300/A 题意 :给你n个数字,让你分成3组,第一组各个数之积要小于0,第二组要大于0,第三组要等于0,符合要求的答案可能会有很多种,输出其中一种. 思路 :表示一开始以为要把n个数分成3组,第一组里的数都大于0这样子,所以一直卡在这儿....因为这个题也相当于special judge了吧,所以要找一个最不容易出错的输出,把n个数排序,最小的肯定是负的(题目保证至少有一个正确答案),所以直接把它分在第一组就行,…
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 ≤ ik < j…
题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利用差分的思想,并且考虑到m比较小,遍历一遍序列,当前点遇到需要改变的时候进行操作,同时更新答案. #include <set> #include <map> #include <queue> #include <deque> #include <stack…
Array GCD 最后的序列里肯定有a[1], a[1]-1, a[1]+1, a[n], a[n]-1, a[n]+1中的一个,枚举质因子, dp去check #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #de…
题目链接: http://codeforces.com/problemset/problem/57/C 题意: 给你一个数n,表示有n个数的序列,每个数范围为[1,n],叫你求所有非降和非升序列的个数. 题解: 由于对称性,我们只要求非降序的个数就可以了(n个数全部相等的情况既属于非升也属于非降) 我们在满足条件的n个数之前加一个虚节点1,在第n个数之后加一个虚节点n,那么考虑这n+2个数组成的非降序列: 假设序列里的第i个数为a[i],我们设xi=a[i+1]-a[i]+1,1<=i<=n+…