Test instructions: Give you an interval, ask A_l%a_ (l+1)%a_ (l+2)%...%a_r value
Analysis: I heard that a number in a given interval is not a lot of position can be a continuous to its model, so think of a more violent there are feasible methods, conjecture complexity should be nlogn. Specifically, from the left to the enumeration of each position,
L[] records the values of all elements in [1,r] that are continuously modulo to r. First put a[1] into the priority queue PQ, for the second position, if Pq.top () >=a[i], take out and modulo, and then update the corresponding position L answer, and put the answer into the priority queue after the modulo, and then handle the interval is 2 of all queries. For the position I, if pq.top () >=a[i], take out and modulo, then update the answer to the corresponding position L, then insert the answer into the PQ after the modulo, and then handle the right interval is I all the queries. Seems to be O (n^2) complexity, in fact, will not reach such a large, for proof ... Not made. XJB guess.
Almost forgot to say that the pit, if the use of offline, the inquiry is the same. (the first to record GG with a map)
/************************************************author:D arktongcreated time:2016/9/10 20:54:34File Name: 1008.cpp*************************************************/#include<bits/stdc++.h>using namespacestd;typedef unsignedLong LongUll;typedefLong LongLL;Const intINF =0x3f3f3f3f;Const DoubleEPS = 1e-9;Const intMAXN =100000+ -; typedef pair<int,int>Pair;intANS[MAXN], L[maxn];vector<Pair>R[MAXN]; (L, id) priority_queue<Pair>cal;//(num, POS)intMain () {intT, cas=1, N; scanf ("%d", &T); while(t--) { while(!cal.empty ()) Cal.pop (); for(intI=0; i<maxn;++i) r[i].clear (); scanf ("%d", &N); for(intI=1; i<=n;++i) scanf ("%d", &L[i]); intL, R, Q; scanf ("%d", &q); for(intI=1; i<=q;++i) {scanf ("%d%d", &l, &R); R[r].push_back (Make_pair (L, i)); } for(intI=1; i<=n;++i) {intL, R; while(!cal.empty () &&cal.top (). first>=L[i]) {L=Cal.top (). Second; R=i; L[L]= Cal.top (). first%L[i]; Cal.pop (); Cal.push (Make_pair (l[l], L)); } cal.push (Make_pair (l[i], i)); for(intj=0; J<r[i].size (); + +j) {L=R[i][j].first; Ans[r[i][j].second]=L[l]; } } for(intI=1; i<=q;++i) printf ("%d\n", Ans[i]); } return 0;}
2016 Dalian Online race 1008 & hdu5875 (priority queue + offline) = uncertain violence