标签:int 定义 printf blog ++ dig turn nbsp def
https://www.cnblogs.com/bestcoder-Yurnero/p/11011868.html
#include<bits/stdc++.h> #define ri register int #define ll long long #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) using namespace std; const inline int read(){ int k = 0, f = 1; char c = getchar(); for(;!isdigit(c); c = getchar()) if(c == ‘-‘) f = -1; for(;isdigit(c); c = getchar()) k = k * 10 + c - ‘0‘; return k * f; } int n, m, maxn[100005][22]; int query(int l, int r){ int k = log2(r - l + 1); return max(maxn[l][k], maxn[r - (1 << k) + 1][k]); } int main(){ n = read(); m = read(); for(ri i = 1; i <= n; ++i){ maxn[i][0] = read(); } for(ri j = 1; j <= 21; ++j) for(ri i = 1; i + (1 << j) <= n + 1; ++i)// i, j反着定义有一丝小难受- - maxn[i][j] = max(maxn[i][j - 1], maxn[i + (1 << (j - 1))][j - 1]); for(ri i = 1; i <= m; ++i){ int l = read(), r = read(); printf("%d\n", query(l, r)); } return 0; }
标签:int 定义 printf blog ++ dig turn nbsp def
原文地址:https://www.cnblogs.com/kojoker/p/12573763.html