hdu5875 Function(暴力)
来源:互联网 发布:mysql数据库存储过程 编辑:程序博客网 时间:2024/06/01 10:28
思路:预处理出右边第一个比它小的数,然后询问的话就跳跳跳就可以了....当然可以随便构造数据让它T...
#include<bits/stdc++.h>using namespace std;const int maxn = 100000+7;int pos[maxn];int a[maxn],n,m;void init(){memset(pos,-1,sizeof(pos));for(int i = n-1;i>=1;i--){ int p = i+1;for(;;){if(a[i]>a[p]){pos[i]=p;break;}if(pos[p]==-1){pos[i]=-1;break;}p = pos[p];}}}int main(){ int T;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i = 1;i<=n;i++)scanf("%d",&a[i]);init();scanf("%d",&m);for(int i = 1;i<=m;i++){int x,y;scanf("%d%d",&x,&y);int ans = a[x];x = pos[x];while(x<=y && x!=-1){ans%=a[x];x=pos[x];}printf("%d\n",ans);}}}
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
0 0
- hdu5875 Function(暴力)
- Function(HDU5875)
- hdu5875 Function (离线处理)
- HDU5875-Function(RMQ + 二分)
- hdu5875 Function
- HDU5875-Function
- hdu5875 Function
- 【HDU5875】Function(RMQ)
- hdu5875 Function (预处理+单调性质)
- hdu5875(思维题)
- hdu5875 Function 模运算 + 单调栈
- Discrete Function(timus1010,暴力)
- 大暴力 Function
- hdu5875(取模的性质,线段树,二分)
- 2016 大连网络赛 & hdu5875 (优先队列+离线)★
- HDU5875 - 大连网赛1008(单调栈)
- URAL 1010 Discrete Function【简单暴力】
- hdu 5875 Function 单调栈 + 暴力
- 非标自动化设备开发流程
- 薪金问题中的四舍五入算法的实现
- leetcode之389. Find the Difference(C++解法)
- 文章标题 UVALive 7035: Built with Qinghuai and Ari Factor(水)
- CodeForces 236 B. Easy Number Challenge
- hdu5875 Function(暴力)
- 设计模式(2)-抽象工厂模式(Abstract Factory)
- 深入理解Java的接口和抽象类
- 国产数据库增量备份测试-神州通用数据库
- android底部导航栏的程序代码
- 几何算法专题2
- Sql Server 2008-闲聊
- 压力机建模和仿真 adams
- 浅谈Java内存分配策略