题解 P6688 可重集
己所欲者,杀而夺之,亦同天赐
解题思路
一定不要用自动溢出的 Hash!!!!!!!
我真的是调吐了。。。
思路非常简单明了 : 需要我们创新一下 Hash。
首先我们的 Hash 要满足无序性。。
因此我们可以把 Hash 值的意义更改一下。
例如: \(x\) 的 Hash 值是 \(base^x\)
在每两个区间维护两个值:原序列最小值以及 Hash 值的加和
这里不可以记录 Hash 因为取 \(\bmod\) 之后大小就不一定了。。
然后直接线段树维护就好了。。。
一定不要用自动溢出的 Hash!!!!!!!
不然哪怕是用 6 个 Hash 也过不了(记录)
然后拍了大概 1e5 组数据,也没拍出错来。。。

感谢@OMA dalao 指出要 取 \(\bmod\),不然我就要 N Hash 了。。
code
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define f() cout<<"Pass"<<endl
#define ls x<<1
#define rs x<<1|1
using namespace std;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch>'9'||ch<'0')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
const int N=1e6+10,INF=1e18,mod=998244353;
const ull base=168717137ull;
int n,m,s[N];
ull p[N];
long double p6[N];
struct Node
{
int mn;
ull has;
long double has6;
Node friend operator + (Node x,Node y)
{
return (Node){min(x.mn,y.mn),(x.has+y.has)%mod};
}
};
struct Segment_Tree
{
int mn;
ull has;
long double has6;
}tre[N<<2];
void push_up(int x)
{
tre[x].has=(tre[ls].has+tre[rs].has)%mod;
tre[x].mn=min(tre[ls].mn,tre[rs].mn);
}
void insert(int x,int l,int r,int pos,int num)
{
if(l==r)
{
tre[x].has=p[num]%mod;
tre[x].mn=num;
return ;
}
int mid=(l+r)>>1;
if(pos<=mid) insert(ls,l,mid,pos,num);
else insert(rs,mid+1,r,pos,num);
push_up(x);
}
Node query(int x,int l,int r,int L,int R)
{
if(L<=l&&r<=R) return (Node){tre[x].mn,tre[x].has};
int mid=(l+r)>>1;
Node ans1=(Node){INF,0ull},ans2=(Node){INF,0ull};
if(L<=mid) ans1=query(ls,l,mid,L,R);
if(R>mid) ans2=query(rs,mid+1,r,L,R);
return ans1+ans2;
}
signed main()
{
n=read();
m=read();
p[0]=1;
for(int i=1;i<N;i++) p[i]=p[i-1]*base%mod;
for(int i=1;i<=n;i++)
s[i]=read();
for(int i=1;i<=n;i++)
insert(1,1,n,i,s[i]);
for(int i=1,opt,x,y,l1,r1,l2,r2;i<=m;i++)
{
opt=read();
if(!opt)
{
x=read();y=read();
insert(1,1,n,x,y);
continue;
}
l1=read();r1=read();l2=read();r2=read();
Node ans1=query(1,1,n,l1,r1);
Node ans2=query(1,1,n,l2,r2);
if(ans1.mn<ans2.mn) swap(ans1,ans2);
if(p[ans1.mn-ans2.mn]*ans2.has%mod==ans1.has%mod)
printf("YES\n");
else printf("NO\n");
}
return 0;
}
题解 P6688 可重集的更多相关文章
- 生成1~n的排列,以及生成可重集的排列
#include <iostream> using namespace std; void printPermutation(int n, int* A, int cur) { if (c ...
- 非负整数可重集去重&排序+获得可重集的全排列的几种方法
非负整数可重集O(n)去重并排序 可重集是指元素可重复的集合,对于在一定区间内的正整数集,比如[1,n],我们可以在不不使用任何额外空间(包括不使用O(1)的空间)的情况下,用O(n)的时间复杂度完成 ...
- 生成1~n的排列(模板),生成可重集的排列(对应紫书P184, P185)
生成1~n的排列: #include<iostream> using namespace std; void print_permutation(int n, int *A, int cu ...
- codevs 1229 数字游戏(可重集的全排列)
传送门 Description Lele 最近上课的时候都很无聊,所以他发明了一个数字游戏来打发时间. 这个游戏是这样的,首先,他拿出几张纸片,分别写上0到9之间的任意数字(可重复写某个数字),然后 ...
- 【NOI2018】归程 题解(kruskal重构树+最短路)
题目链接 题目大意:给定一张$n$个点$m$条边的无向图.每条边有长度和海拔.有$Q$次询问,每次给定起点$v$和当天水位线$p$,每次终点都是$1$.人可以选择坐车或走路,车只能在海拔大于水位线的路 ...
- 【HNOI2012】永无乡 题解(并查集+线段树合并)
题目链接 给定一张含$n$个点$m$条边的无向图,每个点有一个重要指数$a_i$.有两种操作:1.在$x$和$y$之间连一条边:2.求$x$所在连通块中重要程度第$k$小的点. ----------- ...
- STL next_permutation(a,a+n) 生成一个序列的全排列。满足可重集。
/** 题目: 链接: 题意: 思路: */ #include <iostream> #include <cstdio> #include <vector> #in ...
- 求重集的r-组合
具体的就不在这里说了,如果有兴趣的可以把我的工程包下载下来看,留个URL http://pan.baidu.com/s/1bnes1HX
- 生成可重集的排序 (白书P184)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...
随机推荐
- Java-Lambda相关使用介绍
频繁使用的语句 Lambda又涉及到comparator和comparable区别(Comparable是实现comparable接口,实现后可以使用Collections.sort或Arrays ...
- sql循环说明
while循环:主要是判断,不能使用表中的ID,临时表是ID自增的,通过自增ID可以查出表ID(语法简单,需要配合其他代码操作表ID)游标循环:可以使用表中的ID ,进行修改等操作(语法难一点,核心代 ...
- 试着给VuePress添加渐进式Web应用(PWA)支持,基于vuepress/plugin-pwa,点亮离线访问
背景 有时候,我们也希望VuePress构建的文档中心能支持离线访问,这时候我们需要给他添加渐进式Web应用(PWA,Progressive Web App)的支持,根据官方文档指引,我们可以借助插件 ...
- 选择适合小企业的CRM软件
随着信息时代的到来和客户掌握的信息变多,大多数企业开始从"以产品为中心"转变为"以客户为中心".为了适应市场的变化,许多企业开始使用客户关系管理软件来提高工作效 ...
- SpringBoot:springBoot注解大全
springboot源码下载 https://github.com/spring-projects/spring-boot/releases 一.注解(annotations)列表 @SpringBo ...
- idea中IDEA优化配置
进入IDEA 设置.两种方法: 1,File -> Settings 2,工具栏有个工具按钮点下(假如没工具栏,View -> 选下Toolbar) 进入设置页面,从上到下,主要是 外观 ...
- pdfkit html转pdf
pdfkit的通用option选项 参考:https://cloud.tencent.com/developer/ask/202116https://www.cnblogs.com/taceywong ...
- Redis中的布隆过滤器及其应用
什么是布隆过滤器 布隆过滤器(Bloom Filter)是由Howard Bloom在1970年提出的一种比较巧妙的概率型数据结构,它可以告诉你某种东西一定不存在或者可能存在.当布隆过滤器说,某种东西 ...
- Vue | 路由守卫面试常考
前言 最近在整理基础,欢迎掘友们一起交流学习 结尾有彩蛋哦! Vue Router 路由守卫 导图目录 路由守卫分类 全局路由守卫 单个路由守卫 组件路由守卫 路由守卫执行的完整过程 路由守卫分类 全 ...
- C语言:指针
#include <stdio.h> #include <stdlib.h> int sum(int a,int b) { int c; c=a+b; printf(" ...