今天学了st表,以及线段树
#include<bits/stdc++.h> #define ll long long #define par pair<ll,ll> #define prr pair<ll,par> #define st first #define nd second #define ld long double #define MX 1000000000000ll #define MO 1000000007ll // #define MO 998244353ll #define MN 0.000001 #define MXM 2000002 #define MXN 1000002 #define PP 131ll #define LG 20 using namespace std; inline void rd(ll &x){x=0;short f=1;char c=getchar();while((c<'0'||c>'9')&&c!='-') c=getchar();if(c=='-') f=-1,c=getchar();while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();x*=f;} inline void pt(ll x){if(x<0) putchar('-'),x=-x;if(x>9) pt(x/10);putchar(x%10+'0');} /* BBBBBBB ZZZZZZZZ MM MM BB BB ZZ MMM MMM BB BB ZZ MMMM MMMM BBBBBBB ZZ MM MM MM MM BB BB ZZ MM MM MM MM BB BB ZZ MM MMM MM BBBBBBB ZZZZZZZZ MM M MM */ ll T=1,n,q,a[MXN],s[MXN],ans; ll st[MXN][LG],nl; ll ask(ll l,ll r){ if(l>r) return -MX; ll x=log2(r-l+1); return max(st[l][x],st[r-(1<<x)+1][x]); } void solve(){ rd(n),rd(q); nl=log2(n); for(ll i=1;i<=n;i++) rd(a[i]),s[i]=s[i-1]+a[i],st[i][0]=a[i]-s[i-1]; for(ll k=1;k<=nl;k++) for(ll i=1;i+(1<<(k-1))<=n;i++) st[i][k]=max(st[i][k-1],st[i+(1<<(k-1))][k-1]); while(q--){ ll l,r; rd(l),rd(r); pt(max(0ll,ask(l+1,r)+s[l-1])),puts(""); } }int main(){while(T--) solve();}
标签:24,BB,MM,ll,st,2025,ZZ,define From: https://www.cnblogs.com/litianyu1969/p/18688805