标签:std bsp display type c++ hid fine tchar ems
#include<bits/stdc++.h> using namespace std; #define LOACL freopen("in","r",stdin);\ freopen("out","w",stdout); const int sz = (int)1e6 + 5; #define CLR(arr,val) memset(arr,val,sizeof(arr)) #define DBG(x) cout<<(#x)<<"="<<x<<endl #define DBG2(x,y) cout<<(#x)<<"="<<x<<"\t"<<(#y)<<"="<<y<<endl #define DBG3(x,y,z) cout<<(#x)<<"="<<x<<"\t"<<(#y)<<"="<<y<<"\t"<<(#z)<<"="<<z<<endl #define FOR(i, a, b) for(int i=(a); i<(b); i++) #define REP(i, a, b) for(int i=(a); i<=(b); i++) #define DOWN(i, a, b) for(int i=(a); i>=(b); i--) #define all(x) x.begin(),x.end() #define low(x) (x)&(-x) #define pb push_back typedef long long ll; typedef double dl; int a[sz][22],n,m; void read(int &x) { x=0; char c = getchar(); int f =1; while(!isdigit(c)) { if(c==‘-‘) f=-1; c=getchar(); } while(isdigit(c)) x=x*10+c-48,c=getchar(); x*=f; } int query(int l,int r) { int k=(int )log2(r-l+1); return max(a[l][k],a[r-(1<<k)+1][k]); } int main() { LOACL read(n),read(m); REP(i,1,n) read(a[i][0]); REP(j,1,21) for(int i=1;i+(1<<j)-1<=n;i++) { a[i][j]=max(a[i][j-1],a[i+(1<<(j-1))][j-1]); } int l,r; REP(i,1,m) { read(l),read(r); cout<<query(l,r)<<"\n"; } return 0; }
话说 这个好像那个lca 就用到了
大体意思就是dp[i][j] 通过 i跳了 2^j 然后到达的地方 ,这样
就可以用扫描 线 进行 扫描 ,上面 query dp[l][k] dp[r-1<<k+1][ k ]
标签:std bsp display type c++ hid fine tchar ems
原文地址:https://www.cnblogs.com/corx/p/9016716.html