標籤:names pac -- main clu mes color const size
吐個槽,我現線上段樹敲得賊熟練,但是樹狀數組和st表這麼強大的東西竟然基本不會!!!啊啊啊,我太菜了!
代碼:
#include<iostream>#include<cstdio>#include<cmath>#include<ctime>#include<queue>#include<algorithm>#include<cstring>using namespace std;#define duke(i,a,n) for(int i = a;i <= n;i++)#define lv(i,a,n) for(int i = a;i >= n;i--)#define clean(a) memset(a,0,sizeof(a))const int INF = 1 << 30;const int N = 300005;typedef long long ll;typedef double db;template <class T>void read(T &x){ char c; bool op = 0; while(c = getchar(), c < ‘0‘ || c > ‘9‘) if(c == ‘-‘) op = 1; x = c - ‘0‘; while(c = getchar(), c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘; if(op) x = -x;}template <class T>void write(T x){ if(x < 0) putchar(‘-‘), x = -x; if(x >= 10) write(x / 10); putchar(‘0‘ + x % 10);}int st[1000005][23],a[1000005],n,m;void build(){ duke(i,1,n) st[i][0] = a[i]; duke(i,1,21) { for(int j = 1;j + (1 << i) - 1 <= n;j++) { st[j][i] = max(st[j][i - 1],st[j + (1 << (i - 1))][i - 1]); } }}void query(int l,int r){ int y = log2(r - l + 1); int maxn = 0; maxn = max(st[l][y],st[r - (1 << y) + 1][y]); printf("%d\n",maxn);}int main(){ read(n);read(m); duke(i,1,n) read(a[i]); build(); while(m--) { int l,r; read(l);read(r); query(l,r); } return 0;}
【模板】st表