Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
1.2 kB
1
Indexable
Never
#pragma GCC optimize("O2,no-stack-protector,unroll-loops")
#define ll long long
#define pb push_back
#define ipar(arr, n) vector<ll> arr(n); for(int i=0;i<n;i++) cin>>arr[i];
#include <cmath>
#include <bits/stdc++.h>
#define pii pair<int, int>;
#define pll pair<ll, ll>;
using namespace std;
 
 
 
void solve(){
    ll n;cin>>n; ipar(arr,n);
    vector<ll>uneq(n,-1); //uneq[i] stores the index of uneqaul no just before i
    for(ll i=1;i<n;i++){
        for(ll j=i-1;j>=0;j--){
            if(arr[j]!=arr[i]) {
                uneq[i]=j;
                break;
            }
        }
    }
    //for(auto i:uneq) cout<<i<<" ";
     ll q; cin>>q;
    while(q--){
        ll l,r; cin>>l>>r;
        l--,r--;
        //cout<<"--------------------"<<"\n";
        bool found=false;
        if(uneq[r]!=-1 && uneq[r]>=l){ // theres a unequal no available an it's within l
            cout<<uneq[r]+1<<" "<<r+1<<"\n";
            found=true;
        }
        
        if(!found) cout<<-1<<" "<<-1<<"\n";
    } 
}
 
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
	cin>>t;
	while(t--) solve();
}
Leave a Comment