General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
245202045 Contestant:
jianhe
1927D - 33 C++17 (GCC 7-32) Accepted 358 ms 104908 KB 2024-02-06 19:25:34 2024-02-07 16:40:31
→ Source
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=2e5+10;
ll T,n,q,l,r,A[N],f[33][N],g[33][N];
ll qrymin(ll l,ll r){
	ll k=log2(r-l+1);
	ll a=f[k][l],b=f[k][r-(1<<k)+1];
	return A[a]<A[b]?a:b;
}
ll qrymax(ll l,ll r){
	ll k=log2(r-l+1);
	ll a=g[k][l],b=g[k][r-(1<<k)+1];
	return A[a]>A[b]?a:b;
}
void st(){
	for(int i=1;i<=n;i++) f[0][i]=i,g[0][i]=i;
	for(int i=1;(1<<i)<=n;i++)
		for(int j=1;j+(1<<i)-1<=n;j++){
			ll l=f[i-1][j],r=f[i-1][j+(1<<i-1)];
			ll l2=g[i-1][j],r2=g[i-1][j+(1<<i-1)];
			f[i][j]=A[l]<A[r]?l:r; 
			g[i][j]=A[l2]>A[r2]?l2:r2; 
		}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>T;
    while(T--){
		cin>>n;
		for(int i=1;i<=n;i++) cin>>A[i];
		st();
		cin>>q;
		while(q--){
			cin>>l>>r;
			ll t1=qrymin(l,r),t2=qrymax(l,r);
			if(t1==t2||A[t1]==A[t2]) cout<<"-1 -1\n";
			else cout<<t1<<" "<<t2<<"\n";
		}
    }
	return 0;
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details