hdu 4630 No Pain No Game 树状数组
来源:互联网 发布:csol刀战优化辅助 编辑:程序博客网 时间:2024/05/18 13:07
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <utility>#include <algorithm>using namespace std;typedef pair<int,int>pii;const int maxn=50005;int n,Q;int a[maxn];int ans[maxn];int Max[maxn];int pre[maxn];vector<pii>q[maxn];vector<int>inzi[maxn];void init(){ for(int i=1;i<=50000;i++) for(int j=i;j<=50000;j+=i)inzi[j].push_back(i);}int getsum(int x){ int res=0; while(x)res=max(res,Max[x]),x-=x&-x; return res;}void update(int x,int val){ while(x<=n)Max[x]=max(val,Max[x]),x+=x&-x;}int main(){// freopen("in","r",stdin); init(); int T; cin>>T; while(T--){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",a+i),q[i].clear(); scanf("%d",&Q); for(int i=0;i<Q;i++){ int l,r; scanf("%d%d",&l,&r); q[l].push_back(make_pair(r,i)); } memset(Max,0,sizeof Max); memset(pre,-1,sizeof pre); for(int i=n;i>=1;i--){ int now=a[i]; for(int j=0;j<inzi[now].size();j++){ int tmp=inzi[now][j]; if(pre[tmp]!=-1)update(pre[tmp],tmp); pre[tmp]=i; } for(int j=0;j<q[i].size();j++){ pii now=q[i][j]; int r=now.first; ans[now.second]=getsum(r); } } for(int i=0;i<Q;i++)printf("%d\n",ans[i]); } return 0;}
0 0
- hdu 4630 No Pain No Game 线段树 树状数组
- HDU 4630 No Pain No Game 树状数组
- hdu 4630 no pain no game 树状数组+离线查询
- HDU 4630 No Pain No Game(离线 + 树状数组)
- hdu 4630 No Pain No Game 树状数组
- HDU 4630 No Pain No Game 树状数组+离线操作
- 树状数组no pain no game(hdu 2013多校contest3)
- No Pain No Game(树状数组)
- hdu 4630 No Pain No Game(树状数组离线操作)
- hdu 4630 No Pain No Game (区间gcd相关x线段树or树状数组)
- hdu-4630-No Pain No Game-(树状数组,离线处理)
- hdu 4630 No Pain No Game
- HDU 4630 No Pain No Game
- HDU 4630 No Pain No Game
- hdu 4630 No Pain No Game
- hdu 4630 No Pain No Game
- HDU-4630-No Pain No Game
- hdu 4630No Pain No Game
- day(3) Cocos2dx输出Log的两种方法
- 我的第一篇CSDN博客
- 高斯消元法(Gauss Elimination) 分析 & 题解 & 模板——czyuan原创
- Android之如何做内存优化
- 007 字符串(keep it up)
- hdu 4630 No Pain No Game 树状数组
- 【java基础】Java内存机制
- LeetCode刷题笔录Binary Tree Post Order Traversal
- 细数六大支持智能手机的JS框架
- 黑马程序员-iOS学习日记(六)面向对象-核心语法(一)
- Android_利用URL实现下载功能
- 10-0. 说反话 (20)
- Eclipse导入Android项目的正确方法
- failed to lazily initialize a collection of role