HDU5875-Function
来源:互联网 发布:深入理解java反射机制 编辑:程序博客网 时间:2024/05/20 08:25
Function
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 851 Accepted Submission(s): 321
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
Source
2016 ACM/ICPC Asia Regional Dalian Online
#include <iostream>#include <cstring>#include <cstdio>using namespace std;int main(){ int t,n,m,l,r,a[100009],next[100009]; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); memset(next,-1,sizeof next); for(int i=1; i<=n; i++) { for(int j=i+1; j<=n; j++) { if(a[j]<=a[i]) { next[i]=j; break; } } } scanf("%d",&m); while(m--) { scanf("%d %d",&l,&r); int x=a[l]; for(int i=next[l]; i<=r; i=next[i]) { if(i==-1) break; x%=a[i]; } printf("%d\n",x); } } return 0;}
0 0
- hdu5875 Function
- HDU5875-Function
- hdu5875 Function
- Function(HDU5875)
- hdu5875 Function(暴力)
- 【HDU5875】Function(RMQ)
- hdu5875 Function (预处理+单调性质)
- hdu5875 Function (离线处理)
- HDU5875-Function(RMQ + 二分)
- hdu5875 Function 模运算 + 单调栈
- hdu5875(思维题)
- hdu5875思维题
- hdu5875 二分加st
- hdu5875(取模的性质,线段树,二分)
- 2016 大连网络赛 & hdu5875 (优先队列+离线)★
- HDU5875 - 大连网赛1008(单调栈)
- Function
- function
- 【华为OJ10】字符个数统计
- Menu总结
- 高级软件工程师之路-函数调用过程
- 机房收费系统之Sub Main
- Java技术回顾之JDBC:JDBC的事务支持
- HDU5875-Function
- LIstView中中SimpleAdapter的getView与listview的onitemclick不共存的问题
- 调试,虚拟环境检测试的一些新想法
- ios大话 观察者模式(Observer)
- ls命令常用方法
- POJ 1679 The Unique MST
- 操作系统
- 浮点数之坑
- 排序函数模板