1 条题解
-
-1
//#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") /* @ mch @ Mar @ problem from:ST 表 & RMQ 问题 */ #include <bits/stdc++.h> using namespace std; #define int long long #define lod long double #define FastIO ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) #define PII pair<int,int> #define gc getchar #define pc putchar #define NDEBUG #define rep(i,n) for(int i=1; i<=n; i++) #define rep2(i,n) for(int i=1; i<=m; i++) #define rep3(i,n) for (int i = 1; i <= n; i++) const int N = 1e5+5; int tree[N<<2],n,m,a[N]; /* struct Node { int Tree; int Trunk; } val[N]; */ void pushup(int root) { tree[root] = max(tree[root<<1],tree[root<<1|1]); } void build(int l,int r,int root) { if(l==r) { tree[root] = a[l]; return; } int Mid = (l+r)>>1; build(l,Mid,root<<1); build(Mid+1,r,root<<1|1); pushup(root); } int query(int l,int r,int root,int L,int R) { if(L<=l && r<=R) return tree[root]; int maxx = -1e9; int Mid = (l+r)>>1; if(L<=Mid)maxx = max(maxx,query(l,Mid,root<<1,L,R)); if(R>Mid)maxx = max(maxx,query(Mid+1,r,root<<1|1,L,R)); return maxx; } signed main(void) { FastIO; cin>>n>>m; rep(i,n) cin>>a[i]; build(1,n,1); rep2(i,n) { int x,y; cin>>x>>y; cout<<query(1,n,1,x,y)<<"\n"; } return 0; }
- 1
信息
- ID
- 7935
- 时间
- 800ms
- 内存
- 125MiB
- 难度
- 5
- 标签
- 递交数
- 159
- 已通过
- 41
- 上传者