Function
Time limit:7000/3500 MS (java/others) Memory limit:262144/262144 K (java/others)
Problem DescriptionThe Shorter, the simpler. With this problem, you should is convinced of this truth.
You is given an arrayAOfNpostive integers, andMQueries in the form(l,R) . A functionF(l,R) (1≤l≤r≤N) is defined as:
F(L,R)={ALF(L,R−1) moda r l =r; l <r
You job was to calculate F(l,R), for each query (l,R ).
Inputthere is multiple test cases.
The first line of input contains a integerT, indicating number of test cases, andTTest cases follow.
For each test case, the first line contains an integern(1≤n≤100000) .
The second line containsNspace-separated positive integers:A1,...,aN (0≤ai≤9) .
The third line contains an integerMDenoting the number of queries.
The followingMLines each contain, integers l,R (1≤l≤r≤N) , representing a query.
Outputfor each query (l,R), output F(l,R) on one line.
Sample Input132 3 311 3
Sample Output2Analysis: Violent transfer can be, (this method is high complexity, to be improved, but can a ... )Reference http://blog.csdn.net/angon823/article/details/52496697Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineVI vector<int>#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)#definePII pair<int,int>#defineLson L, Mid, rt<<1#defineRson mid+1, R, rt<<1|1Const intmaxn=1e5+Ten;using namespacestd;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p;p=p*p;q>>=1;}returnF;}intN,M,K,T,Q,A[MAXN],R[MAXN];intMain () {inti,j; scanf ("%d",&t); while(t--) {scanf ("%d",&N); Rep (I,1, N) scanf ("%d",&A[i]); memset (R,inf,sizeofR); R[n]=inf; for(i=n-1; i>=1; i--) {k=i+1; while(k<=N) {if(a[i]>A[k]) {R[i]=K; Break; } k=R[k]; }} scanf ("%d",&q); while(q--) { intX,y,ans; scanf ("%d%d",&x,&y); Ans=A[x]; while(r[x]<=y) {ans%=A[r[x]]; X=R[x]; } printf ("%d\n", ans); } } //System ("Pause"); return 0;}
2016 Dalian Network Game Function