hdu5875 Function (离线处理)
来源:互联网 发布:sketch 激活码 mac 编辑:程序博客网 时间:2024/06/05 20:14
Problem Description
The shorter, the simpler. With this problem, you should be convinced of this truth.
You are given an arrayA of N postive integers, and M queries in the form (l,r) . A function F(l,r) (1≤l≤r≤N) is defined as:
F(l,r)={AlF(l,r−1) modArl=r;l<r.
You job is to calculateF(l,r) , for each query (l,r) .
You are given an array
You job is to calculate
Input
There are multiple test cases.
The first line of input contains a integerT , indicating number of test cases, and T test cases follow.
For each test case, the first line contains an integerN(1≤N≤100000) .
The second line containsN space-separated positive integers: A1,…,AN (0≤Ai≤109) .
The third line contains an integerM denoting the number of queries.
The followingM lines each contain two integers l,r (1≤l≤r≤N) , representing a query.
The first line of input contains a integer
For each test case, the first line contains an integer
The second line contains
The third line contains an integer
The following
Output
For each query(l,r) , output F(l,r) on one line.
Sample Input
132 3 311 3
Sample Output
2
#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include <vector>#include <queue>using namespace std;#define LL long long#define INF 0x3f3f3f3f3f3f3f3fint T;int n,m;int a[120000];int net[120000];int pos[120000];int ans[120000];int cnt=0;struct Node{ int l,r,id;} node[120000];bool cmp(Node a,Node b){ if(a.l!=b.l) return a.l<b.l; return a.r<b.r;}int main(){ while(scanf("%d",&T)!=EOF) { while(T--) { scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); cnt=0; a[n+1]=0; pos[cnt]=n+1; for(int i=n; i>=1; i--) { while(a[i]<=a[pos[cnt]]) cnt--; net[i] = pos[cnt]; pos[++cnt] = i; } scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%d%d",&node[i].l,&node[i].r); node[i].id=i; } sort(node+1,node+n+1,cmp); node[0].l=node[0].r=node[0].id=0; int pre=0; for(int i=1; i<=n; i++) { if(node[pre].l==node[i].l) { int re = ans[node[pre].id]; int pp = net[node[pre].r]; while(pp <= node[i].r&&re) { re %=a[pp]; pp = net[pp]; } ans[node[i].id]=re; pre=i; } else { int re = a[node[i].l]; int pp = net[node[i].l]; while(pp <= node[i].r &&re) { re %= a[pp]; pp=net[pp]; } ans[node[i].id]=re; pre = i; } } for(int i=1; i<=n; i++) printf("%d\n",ans[i]); } } return 0;}
Problem Description
The shorter, the simpler. With this problem, you should be convinced of this truth.
You are given an arrayA of N postive integers, and M queries in the form (l,r) . A function F(l,r) (1≤l≤r≤N) is defined as:
F(l,r)={AlF(l,r−1) modArl=r;l<r.
You job is to calculateF(l,r) , for each query (l,r) .
You are given an array
You job is to calculate
Input
There are multiple test cases.
The first line of input contains a integerT , indicating number of test cases, and T test cases follow.
For each test case, the first line contains an integerN(1≤N≤100000) .
The second line containsN space-separated positive integers: A1,…,AN (0≤Ai≤109) .
The third line contains an integerM denoting the number of queries.
The followingM lines each contain two integers l,r (1≤l≤r≤N) , representing a query.
The first line of input contains a integer
For each test case, the first line contains an integer
The second line contains
The third line contains an integer
The following
Output
For each query(l,r) , output F(l,r) on one line.
Sample Input
132 3 311 3
Sample Output
2
0 0
- hdu5875 Function (离线处理)
- Function(HDU5875)
- hdu5875 Function(暴力)
- HDU5875-Function(RMQ + 二分)
- hdu5875 Function
- HDU5875-Function
- hdu5875 Function
- 【HDU5875】Function(RMQ)
- 2016 大连网络赛 & hdu5875 (优先队列+离线)★
- hdu5875 Function (预处理+单调性质)
- hdu5875(思维题)
- hdu5875 Function 模运算 + 单调栈
- 离线处理
- hdu5875(取模的性质,线段树,二分)
- HDU5875 - 大连网赛1008(单调栈)
- hdu4630(树状数组+离线处理)
- hdu 5057(树状数组+离线处理)
- [ACM] HDU 5139 Formula (离线处理)
- 设置Button或ImageButton的背景颜色的透明度
- 面向对象的过程
- 解析android中系统日期时间的获取
- 2018年ACMICPCWORLDFINAL冠军在2016.9.11干的蠢事
- keil 中回调函数参数限制
- hdu5875 Function (离线处理)
- 如何让图标和文字显示在同一行
- vi/vim命令-文本编辑工具
- Win 7 下eclipse添加Courier New字体
- 精读《 C++ Primer》笔记(一):1-5章 输入输出,指针,头文件,string,vector
- windows下eclipse中android项目关联android library 项目库
- windows系统下搭建tomcat服务器
- Android入门二(五大布局)
- 微机原理==第二章16位和32位微处理器(2)