prologue

数组范围一定要看好了开,不然容易我一样,调试调了一页多。

还有就是不要傻乎乎地只跑一次和哈希,因为和哈希(从下面地佬的题解中才知道)它其实算作是一种 trick(类比SA(Stimulate_anneal)。

analysis

这个题目的第二个询问时询问一个区间里面出现过的正整数的次数是否为 \(k\) 的倍数。这个题可以说是这个题目的 pro plus 版本。这样子的话么,我们就可以往这个方面考虑。

我们再继续分析这个题目。

我们和上面所示的例题一样,将统计出现次数,哈希一下。

然后,我们记 \(G(l, r)\) 为一个区间里面的数字哈希和,如果满足题目中的性质,那么我们会有:

\[k \mid G(l, r)
\]

证明:取其中的一个数 \(a_i\) 为例,出现了 \(k\) 次则相加和一定为 \(k\) 的

\(a_i\)倍数。对于满足条件的 \(G(l, r)\) 其中每一个数都满足条件,由此得证。

最后我们就转化成了给每一个数字的哈希值求和,然后看这个值能否整除 \(k\)。

还有就是对于这个里面的时候进行离散化要考虑好常数问题,然后选择合适的方法进行离散化。

然后我们分析一下正确性,对于一个区间限制最坏的情况是存在一对数 \((x, y)\),满足 \(k \mid cnt_x + cnt_y, k \nmid cnt_x, k\nmid cnt_y\) 那么这个时候我们判断错误当且仅当 \((x, y)\) 全被选,或者 \((x, y)\) 全不选。我们随机判错的概率是 \(\frac{1}{2}\),所以当我们进行了 \(B\) 次判断,我们判错的概率就是 \(\frac{1}{2^B}\),这个时候取到 \(B = 30\) 即可。

code time

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rl register ll
#define lowbit(x) (x & -x)
mt19937 rnd; // 一个很好用的随机化,与rand相比这个会更快一点,听别的题解们说不用这个会被卡/fad template <class T> // 快读板子 inline void read(T &res)
{
char ch; bool f = 0 ;
while((ch = getchar()) < '0' || ch > '9') f |= ch == '-';
res = ch ^ 48;
while((ch = getchar()) <= '9' && ch >= '0') res = (res << 1) + (res << 3) + (ch ^ 48);
res = f ? ~res + 1 : res;
} const ll N = 3e5 + 10; ll n, a[N], m, lst[N]; ll tr[N], ls[N << 2], tot, rd[N << 2]; // 想好数组大小 bool ans[N]; struct node
{
ll op, x, y, z;
}q[N << 1]; inline ll Rand(ll l, ll r)
{
uniform_int_distribution<ll>distribution(l, r);
return distribution(rnd);
} inline void add(ll x, ll c)
{
for(; x <= n; x += lowbit(x)) tr[x] += c;
} inline ll sum(ll x)
{
ll res = 0;
for(; x; x -= lowbit(x)) res += tr[x];
return res;
} int main()
{
// freopen("1.in", "r", stdin), freopen("1.out", "w", stdout); read(n), read(m); for(rl i=1; i <= n; ++ i)
{
read(a[i]);
ls[ ++ tot] = a[i];
} for(rl i=1; i <= m; ++ i)
{
read(q[i].op), read(q[i].x), read(q[i].y);
if(q[i].op == 1) ls[ ++ tot] = q[i].y;
else read(q[i].z);
} sort(ls + 1, ls + 1 + tot); tot = unique(ls + 1, ls + 1 + tot) - ls - 1; for(rl i=1; i <= n; ++ i) a[i] = lower_bound(ls + 1, ls + 1 + tot, a[i]) - ls; for(rl i=1; i <= m; ++ i) if(q[i].op == 1) q[i].y = lower_bound(ls + 1, ls + 1 + tot, q[i].y) - ls; memset(ans, 1, sizeof ans); for(rl i=0; i < 30; ++ i)
{
memset(tr, 0, sizeof tr);
for(rl i=1; i <= tot; ++ i) rd[i] = Rand(1, 1e9);
for(rl i=1; i <= n; ++ i) lst[i] = a[i];
for(rl i=1; i <= n; ++ i) add(i, rd[a[i]]);
for(rl i=1; i <= m; ++ i)
{
if(q[i].op == 1)
{
add(q[i].x, -rd[lst[q[i].x]]);
lst[q[i].x] = q[i].y;
add(q[i].x, rd[lst[q[i].x]]);
}
else ans[i] &= ((sum(q[i].y) - sum(q[i].x - 1)) % q[i].z == 0);
}
} for(rl i=1; i <= m; ++ i) if(q[i].op == 2) (ans[i] == 1) ? puts("YES") : puts("NO");
return 0;
}

随机推荐

  1. 【技术积累】Mysql中的SQL语言【技术篇】【二】

    什么是多表查询?如何在MySQL中进行多表查询? 多表查询就是在一个查询中涉及到多个表,通过特定的关联方式连接多个表,并根据条件从中查询出所需要的数据. 多表查询是关系型数据库中最为基础的应用之一. ...

  2. go web学习(四)

    跟着b站https://space.bilibili.com/361469957 杨旭老师学习做的笔记 中间件 什么是中间件 请求----> 中间件 ----> Handler 响应 &l ...

  3. LEA: Improving Sentence Similarity Robustness to Typos Using Lexical Attention Bias 论文阅读

    LEA: Improving Sentence Similarity Robustness to Typos Using Lexical Attention Bias 论文阅读 KDD 2023 原文 ...

  4. python开发之远程开发工具对比

    前言 除了本地开发外,还有一种常见的开发方式就是远程开发,一般情况是一台Windows或mac笔记本作为日常使用的电脑,另有一台linux服务器作为开发服务器.开发服务器的性能往往较强,这样远程开发的 ...

  5. GoFrame v2.5 版本发布,企业级 Golang 开发框架

    大家好啊,GoFrame 框架今天发布了 v2.5.0 正式版本啦! 本次版本主要是对已有功能组件以及开发工具上的改进工作.其中,开发工具新增了 gf gen ctrl 命令,以规范化定义.开发 AP ...

  6. Redis核心技术与实践 01 | 基本架构:一个键值数据库包含什么?

    原文地址:https://time.geekbang.org/column/article/268262 个人博客地址:http://njpkhuan.cn/archives/redis-he-xin ...

  7. .net core 因路径原因导致的JSON解析错误

    因解析json配置文件导致的错误: JsonReaderException: '0xEF' is an invalid escapable character within a JSON string ...

  8. test20230304考试总结(2023春 · 字符串)

    前言 赛时得分明细: A B C D Total Rank 100 100 0 70 270 2 C题如此说道:字符串没有学好的报应!! A. P4391 [BOI2009]Radio Transmi ...

  9. Django错误:ERRORS: ?: (staticfiles.E001) The STATICFILES_DIRS setting is not a tuple or list. HINT: Perhaps you forgot a trailing comma?

    报错的原因是因为我们的STATICFILES_DIRS赋值时,形式不对,其应该赋数组对象,具体如下: 找到settings.py文件, 把 STATICFILES_DIRS=(os.path.join ...

  10. SwiftUI的认识与使用

      SwiftUI简介 SwiftUI是苹果推出的一个新的UI框架,它使用了声明的方式,通过视图,基础控件和布局控件来进行页面的开发. SwiftUI具有跨平台性,一份SwiftUI代码可以同时跑在i ...