#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
long long int t,n,w,k,x,y;
cin>>t;
while(t--)
{cin>>n>>w;
long long int a[n];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<w;i++)
{cin>>k;
if(k==1) {cin>>x>>y;long long int max=0;
for(int j=x;j<=y;j++){if(a[j]>max)max=a[j];}
cout<<max<<endl;}
else if(k==2){cin>>x>>y;long long int sum=0;
for(int j=x;j<=y;j++){sum+=a[j];}
cout<<sum/(y-x+1)<<endl;}
else {cin>>x;
cout<<a[x]<<endl;
}
}
}
return 0;
}
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
long long int t,n,w,k,x,y;
cin>>t;
while(t--)
{cin>>n>>w;
long long int a[n];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<w;i++)
{cin>>k;
if(k==1) {cin>>x>>y;long long int max=0;
for(int j=x;j<=y;j++){if(a[j]>max)max=a[j];}
cout<<max<<endl;}
else if(k==2){cin>>x>>y;long long int sum=0;
for(int j=x;j<=y;j++){sum+=a[j];}
cout<<sum/(y-x+1)<<endl;}
else {cin>>x;
cout<<a[x]<<endl;
}
}
}
return 0;
}
測資有負數,要把max指定成第1個數。