bzoj3381[usaco2004 Open]cave Cows 2 The two cows in the cave
Test instructions
RMQ problem. Sequence length ≤25000, number of questions ≤25000.
Exercises
Double.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineInc (I,J,K) for (int i=j;i<=k;i++)5 #defineMAXN 251006 using namespacestd;7 8InlineintRead () {9 CharCh=getchar ();intf=1, x=0;Ten while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} One while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); A returnf*x; - } - intn,m,lg[maxn],mn[maxn][ -]; the intMain () { -N=read (); M=read (); Inc (I,1, N) mn[i][0]=read (); - for(intI=0;1<<i<=n;i++) lg[1<<i]=i; Inc (I,1, N)if(!lg[i]) lg[i]=lg[i-1]; - for(intI=1;1<<i<=n;i++) Inc (J,1, N)if(J+ (1<<i)-1<=n) Mn[j][i]=min (mn[j][i-1],mn[j+ (1<< (I-1))][i-1]); +Inc (I,1, M) { - intA=read (), B=read (), c=lg[b-a+1]; +printf"%d\n", Min (mn[a][c],mn[b-(1<<C) +1][c])); A } at return 0; -}
20160912
bzoj3381[usaco2004 Open]cave Cows 2 The two cows in the cave