hdu4630:http://acm.hdu.edu.cn/showproblem.php?pid=4630

题意:给定一个排序,求区间最大GCD。

题解:离散树状数组。首先把查询按左端点从大到小排序。然后用树状数组来维护每个位置出现的最大的公约数。枚举每个数的约数,记录到当前位置为止,上一个x的倍数出现的位置b[x];

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<vector>
 6 using namespace std;
 7 const int N=5e4+19;
 8 int a[N],c[N],b[N],ans[N];
 9 int n,m;
10 int lowbit(int x){
11    return x&(-x);
12 }
13 void add(int x,int val){
14     while(x<=n){
15         c[x]=max(c[x],val);
16         x+=lowbit(x);
17     }
18 }
19 int getsum(int x){
20    int sum=0;
21    while(x>0){
22      sum=max(sum,c[x]);
23      x-=lowbit(x);
24    }
25    return sum;
26 }
27 struct Node{
28   int l,r;
29   int id;
30   bool operator<(const Node a)const{
31     return l>a.l;
32   }
33 }num[N];
34 int main(){
35     int T;
36     scanf("%d",&T);
37     while(T--){
38         scanf("%d",&n);
39         memset(a,0,sizeof(a));
40         memset(c,0,sizeof(c));
41         memset(b,0,sizeof(b));
42         for(int i=1;i<=n;i++)
43           scanf("%d",&a[i]);
44           scanf("%d",&m);
45           for(int i=1;i<=m;i++){
46             scanf("%d%d",&num[i].l,&num[i].r);
47             num[i].id=i;
48           }
49         sort(num+1,num+m+1);
50         int j=n;
51         for(int i=1;i<=m;i++){
52             for(;j>=num[i].l;j--){
53                for(int k=1;k*k<=a[j];k++){
54                    if(a[j]%k==0){
55                        if(b[k]){
56                         add(b[k],k);
57                        }
58                         b[k]=j;
59                       if(k*k!=a[j]){
60                          if(b[a[j]/k]){
61                             add(b[a[j]/k],a[j]/k);
62                          }
63                          b[a[j]/k]=j;
64                       }
65                    }
66                }
67              }
68            ans[num[i].id]=getsum(num[i].r);
69          }
70      for(int i=1;i<=m;i++)
71         printf("%d\n",ans[i]);
72     }
73 }

View Code

转载于:https://www.cnblogs.com/chujian123/p/4004793.html

No Pain No Game相关推荐

  1. etymon word write alb pain high alt increase large agency ag lose weight fat assist out~3

    1● alb 2● write =====>rait 1● alg 2● pain 痛,疼痛 1● alt 2● high 高 1● ampl 2● large =====>la:dʒ 大 ...

  2. pain point

    we have got that information brief explorationary purposes Do you interest in the technology in the ...

  3. 文献记录(part9)--A biclustering-based method for market segmentation using customer pain points

    学习笔记,仅供参考,有错必究 关键词:双聚类;客户痛点;市场细分;BCBimax算法 文章目录 A biclustering-based method for market segmentation ...

  4. 迟来的2021年终总结,2022已开始,Good luck every one! No pain No gain!

    击上方"嵌入式应用研究院",选择"置顶/星标公众号" 干货福利,第一时间送达! 时光如影,岁月如梭.2021年就这么过去了.新的一年里,祝大家新年快乐,虎年行大 ...

  5. anytime you feel the pain,hey,dear,refrain

    最近好像有点抱怨太多了,While,Complaint means nothing. 今天发现薰衣草还留着两三个小花苞,决定好好地灌溉,好好地照顾,让她每天晒晒太阳,在阳光最强烈的时候带回北屋乘乘凉, ...

  6. Non-contact Pain Recognition from Video Sequences with Remote Physiological Measurements Prediction

    IJCAI21论文疼痛状态检测 Non-contact Pain Recognition from Video Sequences with Remote Physiological Measurem ...

  7. Pain and Problems(配图笔记)

    Pain and problems 配图笔记 of <The Road Less Travelled> Life is difficult. This is taught in many ...

  8. HDU 4630 No Pain No Game(树状数组)

    题目链接 看的别人的题解,离线之后,按r排序,枚举1-n,利用pre[j],存上次j的倍数出现的位置,树状数组里统计的当前位置到最后的最大值,树状数组是求区间最值其实应该很麻烦的,但是此题用法只是求到 ...

  9. HDU 4630 No Pain No Game 树状数组+离线操作

    题意:给一串数字,每次查询[L,R]中两个数的gcd的最大值. 解法:容易知道,要使取两个数让gcd最大,这两个数最好是倍数关系,所以处理出每个数的所有倍数,两两间根据倍数关系形成一条线段,值为该数. ...

  10. No Pain No Game HDU - 4630(gcd+线段树+离线处理)

    Life is a game,and you lose it,so you suicide. But you can not kill yourself before you solve this p ...

最新文章

  1. 浙大版《C语言程序设计(第3版)》题目集 练习2-17 生成3的乘方表 (15 分)
  2. DataGrid中选择列文本根据绑定数据不同显示为不同颜色的处理办法
  3. css表格文字超数量就竖排_绝了,超轻量级中文 OCR,你值得拥有
  4. mysql group by 区间_SQL按区间进行group by
  5. python函数def中import_在Python中使用def函数时出现名称错误
  6. vCenter Converter Standalone使用文档
  7. 如何使用使用PS批量制作字幕
  8. 梦网云通讯平台单条短信发送接口single_send说明
  9. M-TOUCH移动端社区论坛类型的网站源码
  10. Python文件读写模式与光标的移动
  11. NLP 之 jieba (结巴)制作词云
  12. i春秋 429-线上赛题(一)Writeup
  13. 国家鼓励的软件企业定期减免企业所得税
  14. 【VSCode】yarn : 无法加载文件 A:\yuke\node\node_gobal\yarn.ps1,因为在此系统上禁止运行脚本。
  15. 二叉树之字形层次遍历
  16. 【摘要】STC系列单片机ISP编程器/烧录器的说明
  17. 浅谈对于封装、继承与多态的理解(Java)
  18. selenium 无头模式截屏
  19. 计算机课设微程序最大值,计算机组成原理课程设计(微程序设计).doc
  20. 关于尔雅平台通识课《创业创新执行力》的考试方法与考试须知

热门文章

  1. 计算机网络—基础概念
  2. matlab2c使用c++实现matlab函数系列教程-expstat函数
  3. AD画封装的血泪教训:有叉的放在外侧
  4. 欧几里得求最大公约数--JAVA递归实现
  5. Flink官方文档学习(三):Standalone Cluster 集群部署
  6. 1、Fiddler 打断点 bpu
  7. ECommon.Dapper 轻量级的dapper扩展
  8. BZOJ1075 : [SCOI2007]最优驾车drive
  9. 第9章 SportsStorePeta 完成购物车
  10. Perl 学习笔记-输入输出