Codeforces Round #752 (Div. 2) E. Extreme Extension

题目链接:https://codeforces.com/contest/1604/problem/E

新知识点: ⌊ m 1 ⌋ , ⌊ m 2 ⌋ , . . . , ⌊ m m ⌋ \lfloor\frac{m}{1}\rfloor,\lfloor\frac{m}{2}\rfloor,...,\lfloor\frac{m}{m}\rfloor 1m,2m,...,mm中最多有 2 m 2\sqrt{m} 2m 个不同的数。
证明:https://math.stackexchange.com/questions/1069460/how-many-distinct-values-of-floorn-i-exists-for-i-1-to-n

d p ( i , x ) dp(i,x) dp(i,x) a [ i ; j ] ( i < = j ) a[i; j](i<=j) a[i;j](i<=j) 在变成合法状态下,以x为起始元素的数组个数。则该值对答案的贡献为 ( i − 1 ) ∗ d p ( i , x ) ∗ ( ⌊ a [ i − 1 ] ⌈ a [ i − 1 ] x ⌉ ⌋ − 1 ) (i - 1)*dp(i, x)*(\lfloor\frac{a[i-1]}{\lceil{\frac{a[i - 1]}{x}}\rceil}\rfloor-1) (i1)dp(i,x)(xa[i1]a[i1]1)

这个 ( i − 1 ) (i-1) (i1)是很巧妙的,因为这个值的影响,不论前面有多少个数都会有贡献。这个式子中其它的值很好推,在想暴力的写法时就能知道了。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
const int MOD = 998244353;

int t, n;
LL a[N], dp[2][N];
vector<int> v[2];

int main(void) {
//	freopen("in.txt", "r", stdin);
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%lld", &a[i]);
		LL ans = 0, k = 1;
		for (int i = n; i > 1; i--) {
			k ^= 1;
			dp[k][a[i]] += 1;
			v[k].push_back(a[i]);
			int last = -1;
			for (int j = 0; j < v[k].size(); j++) {
				int x = v[k][j];
				int f = (a[i - 1] + x - 1) / x; // a[i] / x 向上取整
				int g = a[i - 1] / f; // floor(a[i]/ceil(a[i]/x)) 
				dp[k ^ 1][g] += dp[k][x];
				ans = (ans + dp[k][x] * (i - 1) % MOD * (f - 1) % MOD) % MOD;
				if (last != g) {
					last = g;
					v[k ^ 1].push_back(g);
				}
				dp[k][x] = 0;
			}
			v[k].clear();
		}
		memset(dp, 0, sizeof(dp));
		v[0].clear(); v[1].clear();
		printf("%lld\n", ans);
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JILIN.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值