st表40pt求调qwq
查看原帖
st表40pt求调qwq
747882
_adil_楼主2023/8/26 21:39
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>
#include<iterator>
#define N 100009
#define INF 0x3f3f3f3f
#define mod 998244353
#define int long long
using namespace std;
typedef long double ldb;
typedef pair<int,int> pii;
int n,m,q;
int st[N][23][6],a[N],b[N];
//0a最小,1a最大,2a非负最小,3a负数最大,4b最小,5b最大
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin>>n>>m>>q;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    st[i][0][0]=a[i],st[i][0][1]=a[i];
    if(a[i]>=0)st[i][0][2]=a[i],st[i][0][3]=-INF;
    else st[i][0][2]=INF,st[i][0][3]=a[i];
  }
  for(int i=1;i<=m;i++){
    cin>>b[i];
    st[i][0][4]=b[i],st[i][0][5]=b[i];
  }
  for(int j=1;(1<<j)<=n;j++){
    for(int i=1;i+(1<<j)-1<=n;i++){
      st[i][j][0]=min(st[i][j-1][0],st[i+(1<<(j-1))][j-1][0]);
      st[i][j][1]=max(st[i][j-1][1],st[i+(1<<(j-1))][j-1][1]);
      st[i][j][2]=min(st[i][j-1][2],st[i+(1<<(j-1))][j-1][2]);
      st[i][j][3]=max(st[i][j-1][3],st[i+(1<<(j-1))][j-1][3]);
    }
  }
  for(int j=1;(1<<j)<=m;j++){
    for(int i=1;i+(1<<j)-1<=m;i++){
      st[i][j][4]=min(st[i][j-1][4],st[i+(1<<(j-1))][j-1][4]);
      st[i][j][5]=max(st[i][j-1][5],st[i+(1<<(j-1))][j-1][5]);
    }
  }
  for(int i=1;i<=q;i++){
    int l1,r1,l2,r2,ans=-INF;
    cin>>l1>>r1>>l2>>r2;
    int len1=log2(r1-l1+1),len2=log2(r2-l2+1);
    int tmp0=min(st[l1][len1][0],st[r1-(1<<len1)+1][len1][0]);
    int tmp1=max(st[l1][len1][1],st[r1-(1<<len1)+1][len1][1]);
    int tmp2=min(st[l1][len1][2],st[r1-(1<<len1)+1][len1][2]);
    int tmp3=max(st[l1][len1][3],st[r1-(1<<len1)+1][len1][3]);
    int tmp4=min(st[l2][len2][4],st[r2-(1<<len2)+1][len2][4]);
    int tmp5=max(st[l2][len2][5],st[r2-(1<<len2)+1][len2][5]);
   // cout<<tmp0<<" "<<tmp1<<" "<<tmp2<<" "<<tmp3<<" "<<tmp4<<" "<<tmp5<<endl;
    if(tmp4>=0)ans=max(ans,tmp1*tmp4);else if(tmp2!=INF) ans=max(ans,tmp2*tmp4);
    if(tmp5>=0)ans=max(ans,tmp3*tmp5);else ans=max(ans,tmp0*tmp5);
    cout<<ans<<endl;
  }
  return 0;
}
2023/8/26 21:39
加载中...