博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5869 Different GCD Subarray Query
阅读量:7039 次
发布时间:2019-06-28

本文共 1326 字,大约阅读时间需要 4 分钟。

离线操作,树状数组,$RMQ$。

这个题的本质和$HDU$ $3333$是一样的,$HDU$ $3333$要求计算区间内不同的数字有几个。

这题稍微变了一下,相当于原来扫描到$i$的之后是更新$a[i]$的情况,现在是更新$log$级别个数的数字(因为以$i$为结尾的区间,最多只有$log$级别种不同的$gcd$)。

求区间$gcd$可以用$RMQ$预处理一下,然后就可以$O(1)$查询了。

#pragma comment(linker, "/STACK:1024000000,1024000000")#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;const double pi=acos(-1.0),eps=1e-6;void File(){ freopen("D:\\in.txt","r",stdin); freopen("D:\\out.txt","w",stdout);}template
inline void read(T &x){ char c=getchar(); x=0; while(!isdigit(c)) c=getchar(); while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}}const int maxn=100000+10;int T,n,Q,a[maxn],dp[maxn][30],c[maxn],pre[maxn*10],ans[maxn];struct X{ int L,R,id;}s[maxn];int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); }void RMQ_init(){ for(int i=0;i
0;i=i-lowbit(i)) res=res+c[i]; return res;}void update(int x,int v){ for(int i=x;i<=n;i=i+lowbit(i)) c[i]=c[i]+v;}int main(){ while(~scanf("%d%d",&n,&Q)) { for(int i=0;i
pos2) continue; if(pre[g]!=0) update(pre[g],-1); update(pos2,1); pre[g]=pos2; pos1--,pos2--; R=pos1-1; if(R<0) break; g=RMQ(R,i); } while(p

 

转载于:https://www.cnblogs.com/zufezzt/p/5866135.html

你可能感兴趣的文章
VS_远程调试
查看>>
centos7修改hostname以及系统编码
查看>>
LVM配置及简介
查看>>
javascript取得浏览器地址及参数方法
查看>>
博为峰Java技术题 ——JavaSE Java实现在不同编码之间进行文件转换
查看>>
Throws与Throw
查看>>
CISCO交换机配置DHCP监听、IP源防护和动态ARP检测
查看>>
php趣味编程 - php求黑色星期五
查看>>
Mysql数据库主从心得整理
查看>>
活动目录排错ID12源Time-service时间服务器问题
查看>>
Windows Server 2003升级Win Ser 2008R2之2003降级
查看>>
Windows Server 2016-配置Windows Defender防病毒排除项
查看>>
由浅入深CIL系列:5.抛砖引玉:判断string是否为空的四种方法的CIL代码看看效率如何?...
查看>>
我的友情链接
查看>>
zabbix安装
查看>>
OSChina 周五乱弹 —— 但愿老死电脑间,不愿鞠躬老板前
查看>>
Maven项目中添加jFinal包以及源文件
查看>>
Android实用笔记——使用ViewPager实现导航
查看>>
深入理解Java虚拟机 读书笔记 之 how to STW
查看>>
有关数据库事务的一些理解
查看>>