Title Link: http://acm.split.hdu.edu.cn/showproblem.php?pid=5875
Test instructions: There are n numbers, M queries, each query has an interval [L, R], ans, ans = a[l]%a[l+1]%a[l+2]%...%a[r];
Method One: It is violence, can only say that the data is too water;
Use pos[i] = J to indicate that the subscript of a <= a[i] after the first element of the elements is J;
Then jump directly to the current position, (I feel that if there are 10e5 strictly decreasing or strictly increasing sequences in the number is the Tle bar) but this is over, I think the data is too weak
#include <stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<vector>#include<queue>using namespacestd;#defineMet (A, b) memset (A, B, sizeof (a))#defineN 100005#defineINF 0x3f3f3f3ftypedefLong LongLL;#defineLson r<<1#defineRson r<<1|1intN, A[n], pos[n], m;intMain () {intT; scanf ("%d", &T); while(t--) {scanf ("%d", &N); for(intI=1; i<=n; i++) scanf ("%d", &A[i]); a[0] =INF; for(intI=1; i<=n; i++) { for(intj=i+1; j<=n; J + +) { if(A[j] <=A[i]) {Pos[i]=J; Break; }}} scanf ("%d", &m); for(intI=1; i<=m; i++) { intL, R; scanf ("%d%d", &l, &R); intAns =A[l]; while(Ans && pos[l]<=r &&L) {ans= ans%A[pos[l]]; L=Pos[l]; } printf ("%d\n", ans); } } return 0;}View Code
Method Two: In each query, with the Segment tree optimization, when the interval [L, R] to find the position of the first <=num;
Function---hdu5875 (Dalian network selection, interval continuous seeking redundancy)